I am trying to extract gmail.com from the aisle where I want only those line matches that do not start with @.
Example: abc@gmail.com (does not match this); www.gmail.com (corresponding to this)
I tried the following: (?!@)gmail\.combut it did not work. This corresponds to both the cases highlighted in the example above. Any suggestions?
(?!@)gmail\.com
You want to have a negative lookbehind if your regular expression supports it, for example, (?<!@)gmail\.comand adds \bto avoid matching foogmail.comz, for example:(?<!@)\bgmail\.com\b
(?<!@)gmail\.com
\b
foogmail.comz
(?<!@)\bgmail\.com\b
[^@\s]*(?<!@)\bgmail\.com\b
Assuming you want to find lines in longer text, do not check for whole lines.
:
[^@\s]* # match any number of non-@, non-space characters (?<!@) # assert that the previous character isn't an @ \b # match a word boundary (so we don't match hogmail.com) gmail\.com # match gmail.com \b # match a word boundary
(?<!@) lookbehind , : gmail.com abc@gmail.com.
(?<!@)
gmail.com
abc@gmail.com
Use this regex using negative lookbehind :
/^.*?(?<!@)gmail\.com$/