javascript - 正则表达式 - 匹配 parsley.js 中的整个单词

标签 javascript html regex parsley.js

如何在 parsley.js 的 data-parsley-pattern 属性中将两个完整单词与 or(|) 操作数匹配?

如您所见,我想匹配 usermoderator 一词。

我尝试过: 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/

相关文章:

regex - 为什么 Groovy 不支持我的正则表达式中的 "OR"实例?

javascript - 在 JSP 中模态提交后处理表单

javascript - 带有 js : true not finding checkbox 的 capybara

javascript - 尝试使用nightmare.js从搜索结果中获取数据,但出现错误: “Cannot read property ' click' of undefined”

javascript - 获取td文本jquery过滤后tr的索引

javascript - jQuery 基于 anchor 生成列表

javascript - 使用javascript上传图片到服务器

javascript - jquery如何在运行时获取数据?

javascript - 在数组中查找模式

regex - 在正常模式下传递数字键作为 vim 函数的参数