Question: How can I pattern match a specific word (word being Find) whilst ignoring any strings that contain a substring (the word Exclude) anywhere within it?
What I want to do is find all patterns that contain the word Find, and exclude any patterns that contain Exclude anywhere within the string.
What I'm expecting in terms of pattern matching are:
Find - Succeed
ExcludeFind - Fail
FineExclude - Fail
xxxFind - Succeed
Findxxx - Succeed
xxxFindxxx - Succeed
ExcludexxxxxxxxxxFind - Fail
FindxxxxxxxxxxExclude - Fail
ExcludexxxxxxxxxxFindxxxxxxxxxxExclude - Fail
The Regex patterns I've made, which vary in terms of results are:
(\bFind\b) - Only works if Find is the only word
(\w?Find\w?) - Pattern matches any word with Find
((\w?Find\w?)([^Exclude])|([^Exclude])(\w?Find\w?)) - Image below
Looking through various Stack posts, I attempted a more sophisticated approach via Positive and Negative lookbehinds, but it doesn't succeed on any patterns.
(?<!Exclude)(Find)(?<=Exclude)
If it were (?<!Exclude)(Find)
then this works but the only two issues ExcludexxxxxxxxxxFind
and FindxxxxxxxxxxExclude
are also succeeding, which I do not want since these strings contain the "Exclude" word.
I thought a wildcard variant may work (?<!Exclude)?(Find)
or something similar, but again, no patterns are matching for this case.
Fine
instead ofFind
.