开发者

Antimatch with Regex

开发者 https://www.devze.com 2023-02-03 21:28 出处:网络
I search for a regex pattern, which shouldn\'t match a group but everything else. Following regex pattern works basicly:

I search for a regex pattern, which shouldn't match a group but everything else.

Following regex pattern works basicly:

index\.php\?page=(?:.*)&tagID=([0-9]+)$

But the开发者_开发百科 .* should not match TaggedObjects.

Thanks for any advices.


(?:.*) is unnecessary - you're not grouping anything, so .* means exactly the same. But that's not the answer to your question.

To match any string that does not contain another predefined string (say TaggedObjects), use

(?:(?!TaggedObjects).)*

In your example,

index\.php\?page=(?:(?!TaggedObjects).)*&tagID=([0-9]+)$

will match

index.php?page=blahblah&tagID=1234

and will not match

index.php?page=blahTaggedObjectsblah&tagID=1234

If you do want to allow that match and only exclude the exact string TaggedObjects, then use

index\.php\?page=(?!TaggedObjects&tagID=([0-9]+)$).*&tagID=([0-9]+)$


Try this. I think you mean you want to fail the match if the string contains an occurence of 'TaggedObjects'

index\.php\?page=(?!.*TaggedObjects).*&tagID=([0-9]+)$
0

精彩评论

暂无评论...
验证码 换一张
取 消