'Regex How to ignore only one url type

I have a problem, where I can't allow a word + any type of url, but I want to ignore the text that contains the url hacking.com

Valid:   Buy Cell Phone at https://storeOfficial.com
Valid:   Buy Cell Phone at https://store.com
Invalid: Buy Cell Phone at https://hacking.com
Invalid: Buy Cell Phone at https://storeOfficial.com and https://hacking.com

My Regex:

^(?=[\w\W]*([\W|_]+|^)(Cell Phone\b|cell phone\b|CELL PHONE\b).*(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-]))


Solution 1:[1]

You can use

(?i)^.*\bCell Phone\b(?!.*(?:ht|f)tps?:\/\/(?:[^.]*\.)?hacking\.com(?=\/|$)).*(?:ht|f)tps?:\/\/\S+

See the regex demo. Details:

  • (?i) - case insensitive flag on
  • ^ - start of a string
  • .* - any text
  • \bCell Phone\b - a whole word Cell Phone
  • (?!.*(?:ht|f)tps?:\/\/(?:[^.]*\.)?hacking\.com(?=\/|$)) - a negative lookahead that fails the match if there are any zero or more chars other than line break chars, as many as possible, then a protocol, then an optional sequence of any zero or more chars other than a . char and then a . char, and then hacking.com string, either at the end of string or immediately followed with a / char
  • .* - any text
  • (?:ht|f)tps?:\/\/\S+ - http://, https://, ftps:// or ftp:// and then one or more non-whitespace chars.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1