Search code examples
cssregexstylish

How can I exclude two terms from regex in userContent.css?


I'm trying to modify certain aspects of the CSS code for my Google search results page. I'm doing this by editing my userContent.css file in Firefox.

I'm trying to modify the main results page (https://www.google.co.uk/search?q=SSD).

But not on the images page (https://www.google.co.uk/search?q=SSD&tbm=isch) or the shopping results page (https://www.google.co.uk/search?q=SSD&tbm=shop).

Based on the answer provided here, I've added this code:

@-moz-document regexp('https://www\\.google\\.co\\.uk.*(?!isch|shop).*')

But it doesn't seem to work to exclude isch or shop.

Can someone please help?

Thanks


Solution

  • Your pattern matches those urls because after matching .uk you use .*(?!isch|shop) which will first match until the end of the string due to .*

    Then asserts if what is on the right is not isch or shop which will be true as all characters are already matched.

    One option could be to use the negative lookahead (?!.*=(?:isch|shop)$) after matching .uk/ to check if the url does not end on =isch or =shop using .* in the negative lookahead followed by $ to assert the end of the string.

    https://www\.google\.co\.uk/(?!.*=(?:isch|shop)$).*$
    

    Regex demo