Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex to find files containing one word but not another [duplicate]

I am trying to quickly find all .java files which contain one term but are missing another term. I'm using MyEclipse 10.7 and its 'Search | File Search' feature, which supports regular expressions.

Will regex work in this scenario? What would the correct regex be?

TIA, Steve

like image 784
Fred Avatar asked Mar 04 '13 19:03

Fred


1 Answers

The only solution I could find to work is the following Regex:

^(?!.[\s\S]*MISSING_TERM).[\s\S]*INCLUDED_TERM.*$

It finds every file which includes INCLUDED_TERM but lacks MISSING_TERM, regardless of the line.

The key is the \s\S, which ensures the whole file is searched and not each line.

like image 140
Fred Avatar answered Nov 16 '22 03:11

Fred