如何在 parsley.js 的 data-parsley-pattern
属性中将两个完整单词与 or(|)
操作数匹配?
如您所见,我想匹配 user
和 moderator
一词。
我尝试过: data-parsley-pattern="/(user|moderator)/"
这是正常的正则表达式,可以与其他标准化正则表达式匹配(如 regex101.com)一起使用:
https://regex101.com/r/kD7sR1/1
最佳答案
请参阅data-parsley-pattern
2.0 documentation :
Validates that a value matches a specific regular expression (regex). Note that patterns are anchored, i.e. must match the whole string. Parsley deviates from the standard for patterns looking like
/pattern/{flag}
; these are interpreted as litteral regexp and are not anchored.
所以,看起来你的正则表达式应该可以工作。
如果没有,请尝试
data-parsley-pattern="/[\s\S]*(user|moderator)[\s\S]*/"
[\s\S]*
将匹配零个或多个字符(任何字符,包括换行符)。
关于javascript - 正则表达式 - 匹配 parsley.js 中的整个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34657454/