草庐IT

Regex-replace-with-function-evalu

全部标签

javascript - 使用 JavaScript RegEx 使用 am 和 pm 验证时间

我不太擅长正则表达式。我有以下时间:12:00am。我需要一个遵循这种格式的Javascript正则表达式:hh:mm[am/pm]varregex=/^(\d\d):(\d\d)\s?(?:AM|PM)?$/; 最佳答案 你几乎完成了,缺少的部分是关于小时数永远不会大于1和分钟数永远不会大于5的十位。我还在末尾添加了“忽略大小写”标志,它接受“am”、“AM”、“Am”、“aM”:varregex=/^([0-1]\d):([0-5]\d)\s?(?:AM|PM)?$/i;限制性更强一些(1≤小时≤12):/^([1-9]|1[0

javascript - AngularJS: "TypeError: undefined is not a function"与 routeProvider

我正在尝试追踪AngularJS中的“TypeError:undefinedisnotafunction”错误。如果您有任何想法,甚至更好,关于如何调试此类内容的建议,我将不胜感激。请注意,这与我正在处理的代码非常相似,但并不完全相同(尽管它在运行时仍然有相同的错误)。追踪:TypeError:undefinedisnotafunctionatupdate(http://localhost:63342/Channels/vendor/angular-route.js:838:13)atScope.$broadcast(http://localhost:63342/Channels/ve

javascript - 类型错误 : undefined is not a function in Angular Resource

当尝试在AngularJS资源上轮询自定义方法copies时,我在angular.js:10033处收到以下错误:(方法copy工作得很好。)TypeError:undefinedisnotafunctionathttps://code.angularjs.org/1.3.0-beta.8/angular-resource.min.js:9:347atArray.forEach(native)atq(https://code.angularjs.org/1.3.0-beta.8/angular.min.js:7:280)atq.then.p.$resolved(https://code

Javascript : Insane boolean test with '!' operator

这个问题在这里已经有了答案:Checklegalcharactersbyregularexpressionbutwithunexpectedresult(2个答案)关闭7年前。在chrome控制台中输入以下函数调用:(function(regex,str){console.log(regex.test(str))console.log(!regex.test(str))console.log(!regex.test(str))console.log(!regex.test(str))console.log(!regex.test(str))})(newRegExp("new","gmi

javascript - 使用 AngularJS 时出现 ".then() is not a function"错误

这是我的JS:self.obj={}self.obj.accessErrors=function(data){varcerrorMessages=[];for(propindata){if(data.hasOwnProperty(prop)){if(data[prop]!=null&&data[prop].constructor==Object){self.obj.fetch[accessErrors](data[prop]);}else{cerrorMessages.push(data[prop]);}}}returncerrorMessages;};self.obj.fetch={

JavaScript replace() 正则表达式按索引号

我有以下字符串和正则表达式:varstring="Dear[toname],[yourname]hasdecidedtosharethis[link]";varpatt=/\[+[A-Za-z0-9]+\]/;我希望能够使用动态输入更改括号中的每个变量。我如何使用match()或replace()来定位此正则表达式的第1、2和3次出现?编辑:目前,如果我执行类似document.write(body.match(patt));的操作,它只会匹配最后一个[link]编辑:整个字符串取自文本框的值。每个括号的值都取自其他文本输入,需要在将文本放回文本框之前插入到字符串中。

javascript - Angular : Update A Function In RealTime

我有一个Controller:$scope.timeAgoCreation=function(order){returnmoment(order.createdAt).fromNow();};在View中:{{timeAgoCreation(order)}}它返回正确的值:9分钟前。但是这个值不是实时更新的。我必须刷新页面。是否可以让它实时更新? 最佳答案 只需将此功能添加到Controller中(不要忘记注入(inject)$timeout服务):functionfireDigestEverySecond(){$timeout(f

javascript - 测试 : You will need to wrap any code with asynchronous side-effects in a run 时出现 Ember 错误

我们已经有一个应用程序正在运行,只是为了CI的目的向它添加测试用例。我们有一个小代码来尝试登录过程并检查在可能的登录状态(如成功、失败、无效帐户帐户被锁定等)之后发生的情况。所以我尝试了以下代码。visit('/login').fillIn('#identification',"testuser").fillIn('#password',"testpass").click('input[type="submit"]')andThen(function(){ok(!exists('button:contains(signin)'),'3.Loginbuttonisnotdisplayed

javascript - Bluebird.JS Promise : new Promise(function (resolve, reject){}) vs Promise.try(function(){})

我什么时候应该使用哪个?以下是一样的吗?新的Promise()示例:functionmultiRejectExample(){returnnewPromise(function(resolve,reject){if(statement){console.log('statement1');reject(thrownewError('error'));}if(statement){console.log('statement2');reject(thrownewError('error'));}});}Promise.try()示例:functiontryExample(){return

javascript - 为什么 string.replace(/\W*/g ,'_' ) 在所有字符前加上?

我一直在学习js中的正则表达式,遇到一个我不明白的情况。我使用以下正则表达式对替换函数进行了测试:/\W*/g并期望它在字符串的开头添加前缀并继续替换所有非单词字符。TheNumberis(123)(234)会变成:_The_Number_is__123___234_这将在字符串前面添加,因为它至少有零个实例,然后替换所有不间断空格和非单词字符。相反,它在每个字符前加上所有非单词字符。_T_h_e__N_u_m_b_e_r__i_s__1_2_3__2_3_4__为什么要这样做? 最佳答案 问题是\W*的意思。它的意思是“0个或多个