我正在使用正则表达式来验证输入。我想匹配确切的字符串“ spe1”和“ spe1.grl”。
到目前为止,我已经编写了以下代码:
'\\b(?!i' + this.stringToIgnore + '\\b)\\w+';
其中this.stringToIgnore ='spe1'
如果我键入以下内容,则可以工作:
“ spe1”(请注意空格)
“ spe1”。
我想输入以下内容进行比赛:
“ spe1”(无需在末尾添加空格或点)
“ spe1.grl”(无需在末尾添加空格或点)
谢谢您的帮助
答案 0 :(得分:0)
使用在线Regex工具稍作停留后,我找到了自己问题的答案。我正在发布它,以防有人需要它:
'\\b(?!' + this.stringToIgnore + '\\b)\\w+';
或
''\\b(?!' + this.stringToIgnore + '|' + this.stringToIgnore.toUpperCase + '\\b)\\w+';
如果用户打开了大写键。