问题描述:

I'm trying to find the regular expression to match only a part of the pattern

For an example text is :

GoodClass.NiceMethod

BadClass.NiceMethod

Badclass2.NiceMethod

Verybadclass.NiceMethod

GoodClass.NiceMethod

BadClass.NiceMethod

Badclass2.NiceMethod

GoodClass.NiceMethod

how can I get all lines where 'NiceMethod' does not follow 'GoodClass'

网友答案:

You can use negative lookbehind:

String regex = "(?<!GoodClass\\.)\\bNiceMethod\\b";
相关阅读:
Top