-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
  • 13,513
  • 14
  • 70
  • 93
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
  • 713,503
  • 59
  • 514
  • 593