Search code examples
regexeclipsemyeclipse

regex to find files containing one word but not another


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?


Solution

  • 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.