草庐IT

match-recognize

全部标签

javascript - JS : Recognize dot or delete in keypress

如果用户按下点(在标准键盘或数字block上),我想执行一些代码。但是如果我把它接过来Keycode(110),这就和删除按钮一样了。我如何识别它们?感谢您的帮助! 最佳答案 删除键(通常在箭头上方)为46,数字小数点为110,键盘周期为190。这是一个非常好的页面,可以了解什么是键码:http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx如果这不能回答您的问题,请重新措辞,因

javascript - 使用 .match 和 .search 的区别

我为coderbyte使用了以下代码:functionVowelCount(str){//codegoesherereturnstr.match(/[aeiou]/gi).length;}//keepthisfunctioncallhere//toseehowtoenterargumentsinJavaScriptscrolldownprint(VowelCount(readline()));我理解大部分代码,除了以下部分:正斜杠和方括号的作用是什么?gi有什么作用?search()和match()有什么区别?我应该在什么情况下使用什么? 最佳答案

JavaScript(正则表达式): excluding matches from output

我有这个文本:nisinontext600elit其中600是动态添加的。我怎样才能得到它?varstr=('nisinontext600elit').match(/text\d+/);alert(str);这会提醒text600,我如何才能只提醒600而无需额外替换单词text(如果可能的话)?感谢任何帮助,谢谢! 最佳答案 varstr=('nisinontext600elit').match(/text(\d+)/);alert(str[1]); 关于JavaScript(正则表达

javascript - 不能将 String.prototype.match 用作 Array.some 的函数吗?

这行不通:vars='^foo';console.log(['boot','foot'].some(s.match));UncaughtTypeError:String.prototype.matchcalledonnullorundefined但是这样做:vars='^foo';console.log(['boot','foot'].some(function(i){returni.match(s)}));这是为什么?我以某种方式想象String.prototype.match函数太“原始”之类的,但究竟是为什么呢?因为我没有使用ES2015,所以第二个版本看起来很冗长。有替代方案吗

javascript - 用 moment.js : Deprecation warning: value provided is not in a recognized RFC2822 or ISO format 排序

我使用Moment解析从API获得的日期,我需要在完成数据收集后对数组进行排序。我目前有这个:myobject.name=name;myobject.time=Moment(ajaxinfo.startdate).format('DD/MM/YYYY');array.push(myobject);//...moredataisadded...array.sort((left,right)=>{returnMoment.utc(left.time).diff(Moment.utc(right.time));});ajaxinfo.startdate是我从API获取的字符串,它看起来像"2

javascript - Sequelize : Find All That Match Contains (Case Insensitive)

我想使用sequelize.js查询模型以获取包含约束的记录。我该怎么做?这是我现在拥有的:Assets.findAll({limit:10,where:["asset_namelike?",'%'+request.body.query+'%']}).then(function(assets){returnresponse.json({msg:'searchresults',assets:assets});}).catch(function(error){console.log(error);});但我收到以下错误:{error:operatordoesnotexist:charact

javascript - 为什么 String.match(/\d*/) 返回一个空字符串?

有人能帮我理解为什么使用\d*返回一个包含空字符串的数组,而使用\d+返回["100"](如预期的那样)。我明白为什么\d+有效,但不明白为什么\d*不起作用。使用*会导致它返回零长度匹配吗?它究竟是如何工作的?varstr='oneto100';varregex=/\d*/;console.log(str.match(regex));//[""] 最佳答案 请记住,match正在寻找它可以找到的与给定正则表达式匹配的第一个子字符串。*意味着可能有零个或更多的东西,所以\d*意味着你正在寻找一个包含零个或多个数字的字符串。如果您输入

javascript - 我如何在 jQuery 中使用 preg_match?

我可以使用preg_match来验证jQuery中的电话号码吗?这是我的代码,它不起作用:if(!preg_match("/^[0-9]{3}-|\s[0-9]{3}-|\s[0-9]{4}$/",phone.val())){phone.addClass("needsfilled");phone.val(phonerror);}HTML 最佳答案 Javascript包含一个正则表达式引擎,可通过string.match()、string.replace()和string.split()函数。例如:varmystring="this

javascript - JS : Filter object array for partial matches

是否可以过滤那些与搜索字符串匹配的对象?constarr=[{title:'Justanexample'},{title:'Anotherexam'},{title:'Somethingdifferent'}]我试过了arr.filter(x=>{returnx.title===searchStr});但这只会过滤完全匹配项,但我需要找到所有部分匹配项。letsearchStr='exam'应该给我两个对象(第一个和第二个),letsearchStr='examp'应该只给我一个对象作为结果。 最佳答案 根据您的问题,我假设您还想匹

javascript - Firebase 为发布请求提供 "path not recognized"错误

我正在使用Firebase来托管我的nodejs应用程序并正在使用CloudFunctions。使用命令firebaseserve--onlyfunctions,hosting我正在部署我的应用程序。我有一个带有action="/putNPK"的表单,并且在从Node运行时完美运行。但是当我通过firebase提供它时,我在提交表单时遇到了这个错误。{"error":{"code":404,"status":"NOT_FOUND","message":"/putNPKisnotarecognizedpath.","errors":["/putNPKisnotarecognizedpat