How to check if a pattern does not exist in a string?
I have some lines below in which I want fetch only those lines where .com does not exist:
Sample Lines :
https://abc.com – Test site
https://testProfile.in – It was created before
Hello World!
https://testWebsite.com
http://localhost/
Regular Expression we need :
^(?:(?!\.com).)*$
Result will be :
https://testProfile.in – It was created before
Hello World!
http://localhost/
Explanation of the regex :
^ : Represents starting of the string.
(?: : Represents starting of the non-capture group
(?! : Represents starting of the negative lookahead
\.com : Represents the character ‘.’ with the substring ‘com’
) : Represents ending of negative lookahead
)* : Represents ending of non-capture group, repeats 0 or more times
$ : Represents ending of the string
Demo Link : https://regex101.com/r/6m4TiZ/1