正则表达式匹配除两个特定字符串(angular / cli 7.3.5,types / node 8.9.4)以外的任何内容

时间:2019-04-30 16:39:37

标签: node.js regex angular

我正在使用正则表达式来验证输入。我想匹配确切的字符串“ spe1”和“ spe1.grl”。

到目前为止,我已经编写了以下代码:

'\\b(?!i' + this.stringToIgnore + '\\b)\\w+';

其中this.stringToIgnore ='spe1'

如果我键入以下内容,则可以工作:

  

“ spe1”(请注意空格)

     

“ spe1”。

我想输入以下内容进行比赛:

  

“ spe1”(无需在末尾添加空格或点)

     

“ spe1.grl”(无需在末尾添加空格或点)

谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

使用在线Regex工具稍作停留后,我找到了自己问题的答案。我正在发布它,以防有人需要它:

'\\b(?!' + this.stringToIgnore + '\\b)\\w+';

''\\b(?!' + this.stringToIgnore + '|' + this.stringToIgnore.toUpperCase + '\\b)\\w+';

如果用户打开了大写键。