I search a way with regex and java to find line of a text with some word and without some other.
Example, i would like to get line who contain both word ice and snow but do not contain tree and ski. Word order is not important.
I beginned to fine line with ice and snow
(ice)*(snow)
That seem to work but if the order is inverted, that don’t work.
edit:
is it possible to return word who have 3 letters or more between the word ice and snow
I agree with @RanRag that regex is overkill in this case, but here’s how it could be done anyway:
(?=...)is a positive lookahead and(?!...)is a negative lookahead. The regex also uses the word boundary\bso that it won’t match parts of words.