I would like to come out with a regex expression that negate the matched results of regex expression: .google.*search
. And, is it possible to achieve it with regex from the regex expression I am trying to negate?
Test data
[1] https://www.google.com/search?newwindow=1&sxsrf=ALeKk02MzEfbUp3jO4Np
[2] https://github.com/redis/redis-rb
[3] https://web.whatsapp.com/
Expected result
Row 2, 3 match the regex pattern and are part of the results.
2
Answers
the following regex does the trick
basically matching the beginning of the line then negating
(?!)
(negative lookahead) your regex.You may use a negative lookahead here:
Demo
The "secret sauce" here is
(?!.*.google..*search)
, which asserts that.google.
followed bysearch
does not occur anywhere within the URL to the right of thehttps://
portion.