开发者

caret/negate for a word in regular expression [duplicate]

开发者 https://www.devze.com 2022-12-16 22:44 出处:网络
This question alread开发者_开发技巧y has answers here: Tempered Greedy Token - What is different about placing the dot before the negative lookahead?
This question alread开发者_开发技巧y has answers here: Tempered Greedy Token - What is different about placing the dot before the negative lookahead? (3 answers) Closed 5 years ago.

[^a-zA-Z] matches anything except a, b, c, .. z, A, B, .. Z

I want the expression that matches anything except (abc) and except (xyz)

I want a regex for image tag.

I tried img.*src - it matches the initial part but between img and src there should not be any other image tag so I put a caret img[^(neither <img nor src=)] how to use ^ with a group of characters?


In your particular case, why don't you just make sure the "src" is inside the same tag?

Do something like <img\s[^>]*\bsrc


Based on the scenario you're describing, it sounds like you want to use a look-ahead instead of a character exclusion.

MatchThis\s*(?!DontMatchThis|OrThis)

This will match "MatchThis", but not if it is is followed by "DontMatchThis" or by "OrThis"

Here's a link if you'd like to learn more about look-aheads and look-behinds in regular expressions: http://www.regular-expressions.info/lookaround.html

0

精彩评论

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