Reputation: 5131
I would like to search a whole project for files that have both ABCKeyword
and XYZKeyword
in the same file. Is this possible?
When I search a whole project with regex (ABCKeyword|XYZKeyword)
, it returns files that have one or the other but not necessarily both.
Upvotes: 1
Views: 189
Reputation: 626845
You can use positive look-aheads:
(?s)^(?=.*\bABCKeyword\b)(?=.*\bXYZKeyword\b)
Only the text that has both will be matched.
See demo
(?s)
makes the .
to match a newline symbol. (?=.*...)
look-aheads check, but do not consume characters, thus only asseting if there is ABCKeyword
or XYZKeyword
further in the text. The \b
word boundaries make sure we only match full words (if you need to match them partially, inside longer words, remove \b
s).
Upvotes: 1