开发者

Help with regex

I got the following regex:

"throw new [a-zA-Z]+Exception"

I want do modify it so that all Argument excepti开发者_开发问答ons ("Argument[a-zA-Z]*Exception") are not included

How do I combine them?


Take a look at this page for more information: http://www.regular-expressions.info/completelines.html

Keep in mind that different regex implementations may not support all of the options available, so YMMV. If you have a regex designer tool that will let you test the expression live, I highly recommend it. You need a negative lookahead expression:

"((?!Argument)[a-zA-Z])*Exception"

Make sure your regex library supports lookahead and negative lookahead expressions.


You need a negative lookbehind. See here for more details. Perl-specific but your particular implementation likely has something similar.

Lookbehind has the same effect, but works backwards. It tells the regex engine to temporarily step backwards in the string, to check if the text inside the lookbehind can be matched there. (?<!a)b matches a "b" that is not preceded by an "a"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜