当前位置: 动力学知识库 > 问答 > 编程问答 >

regex - Regular expression to fetch lines evaluating only one part of a string, java

问题描述:

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";
分享给朋友:
您可能感兴趣的文章:
随机阅读: