-5

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'

Faraj Farook
  • 14,385
  • 16
  • 71
  • 97
Sivakumar
  • 13
  • 1
  • 5
  • Possible duplicate of [Using Java to find substring of a bigger string using Regular Expression](http://stackoverflow.com/questions/600733/using-java-to-find-substring-of-a-bigger-string-using-regular-expression) – angelcool.net Oct 29 '15 at 18:05

1 Answers1

1

You can use negative lookbehind:

String regex = "(?<!GoodClass\\.)\\bNiceMethod\\b";
anubhava
  • 761,203
  • 64
  • 569
  • 643