简体   繁体   English

ng-pattern用于angularjs错误行为

[英]ng-pattern for angularjs wrong behaviour

i am trying to work with ng-pattern but it throw an error. 我正在尝试使用ng-pattern,但是会引发错误。 i want to validate a duration of time with the follwing pattern : 我想用以下模式验证持续时间:

((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\\s?(?:am|AM|pm|PM))?)

but i have this error : 但我有这个错误:

Lexer Error: Unexpected next character at columns 76-76 [] in expression [((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\\s?(?:am|AM|pm|PM))?]. Lexer错误:表达式[[((?:(?:[0-1] [0-9])|(?:[2] [0-3])|(? ????:[0-9])):(:[0-5] [0-9])(:: [0-5] [0-9])(:\\ S(?:我|? AM | PM | PM))]。

it seems that i have problem with back slash but what i know that if i want escaping back slash i have to make two back slash "\\". 似乎我在反斜杠方面有问题,但是我知道如果我想转义反斜杠,我必须使两个反斜杠“ \\”。 the version of angularjs is 1.2.rc2 angularjs的版本是1.2.rc2

You are actually escaping a white space character. 您实际上是在转义空白字符。 \\s is a white space character in a regular expression so by doing \\\\s you are escaping the white space expression and because of this you are searching for a slash followed by an s: \\s \\s是正则表达式中的空格字符,因此通过执行\\\\s可以转义空格表达式,因此您要搜索斜线后跟s: \\s

What you might need is an extra closing bracket somewhere there... 您可能需要的是在该处的一个额外的结束括号...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM