Reputation: 945
I currently have this regex:
/\w+@\w+\.\w+/
It works great for a string like this one:
[email protected], [email protected], [email protected]
However, it doesn't work for emails with two periods before or after the "@", for example:
[email protected]
How can I modify the regex for it to work with the second string as well?
Thanks! : )
Upvotes: 1
Views: 413
Reputation: 10380
Use a character class instead of \w
and add .
into it. Something like this:
/^[a-zA-Z0-9_.]+@[a-zA-Z0-9_.]+$/
Upvotes: 1
Reputation: 3232
That's not surprising given you've hardcoded one period in your regex. Use \S+
to match any non-whitespace character:
>>> re.findall(r"\S+@\S+", "[email protected]")
['[email protected]']
Upvotes: 0