这个正则表达式出了什么问题?

时间:2020-12-08 22:34:43

I have the regular expression below however it still seems to match when it should not

我有下面的正则表达式,但它似乎仍然匹配不应该

^article\/article_story\.aspx(\?id\=(?!1211)[0-9]{1,4})?$

So effectively if the ID equals to 1211 it should not match and the expression is passed however if it matches say ID 1212 it performs the necesarry task however it still seems to match when the ID is indeed 1211

如果有效,如果ID等于1211它不应该匹配并且表达式被传递,但是如果匹配则说ID 1212它执行必要的任务但是当ID确实是1211时它似乎仍然匹配

1 个解决方案

#1


3  

I don't see it matching 1211 : http://regexr.com?2uam7

我认为它不匹配1211:http://regexr.com?2uam7


And you are unnecessarily complicating it with a huge regex and the (!...). You can just match the id part ( groups ) and then see if it is not 1211. It is not necessary to do everything in regex.

并且你使用巨大的正则表达式和(!...)不必要地复杂化它。您可以匹配id部分(组),然后查看它是否不是1211.没有必要在正则表达式中执行所有操作。

#1


3  

I don't see it matching 1211 : http://regexr.com?2uam7

我认为它不匹配1211:http://regexr.com?2uam7


And you are unnecessarily complicating it with a huge regex and the (!...). You can just match the id part ( groups ) and then see if it is not 1211. It is not necessary to do everything in regex.

并且你使用巨大的正则表达式和(!...)不必要地复杂化它。您可以匹配id部分(组),然后查看它是否不是1211.没有必要在正则表达式中执行所有操作。