I have a use case where I am searching for a particular sub string in a string and if that particular string contains another particular sub string I want it to be rejected.
Ex:
pikachu_is_the_best_ever_in_the_world_go_pikachumew_is_the_best_ever_in_the_world_go_mewraichu_is_the_best_ever_in_the_world_go_raichu
I want my Regex expression to pick up the string having the word "best" and not the word "mew", i.e the first and third string.
I have tried combining ^(.*best).*$ and ^((?!mew).)*$ into the below expressions and the second regex one only ignores words if "mew" is present in the start of the string.
^(.*best)((?!mew).).*$And have tried
^((?!mew).)(.*best).*$ 5 1 Answer
- Ctrl+F
- Find what:
^(?=.*best)(?:(?!mew).)*$ - check Wrap around
- check Regular expression
- DO NOT CHECK
. matches newline - Search in document
Explanation:
^ : start of line
(?= : positive lookahead .* : 0 or more any character but newline best : literally "best"
) : end lookahead
(?: : start non capture group (?! : negative lookahead, make sure we don't have mew : literally "mew" ) : end lookahead . : any character but newline
)* : group may appear 0 or more times
$ : end of line 3