I am learning regex and am having trouble getting google
from email address
String
[email protected]
I just want to get google, not google.com
Regex:
[^@].+(?=\.)
Result: https://regex101.com/r/wA5eX5/1
From my understanding. It ignore @
find a string after that until .
(dot) using (?=\.)
What did I do wrong?
[^@]
means "match one symbol that is not an @
sign. That is not what you are looking for - use lookbehind (?<=@)
for @
and your (?=\.)
lookahead for \.
to extract server name in the middle:
(?<=@)[^.]+(?=\.)
The middle portion [^.]+
means "one or more non-dot characters".
Demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With