skip to Main Content

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


  1. the following regex does the trick

    ^(?!.+google.*search)
    

    basically matching the beginning of the line then negating (?!) (negative lookahead) your regex.

    Login or Signup to reply.
  2. You may use a negative lookahead here:

    https?://(?!.*.google..*search).*
    

    Demo

    The "secret sauce" here is (?!.*.google..*search), which asserts that .google. followed by search does not occur anywhere within the URL to the right of the https:// portion.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search