there is a bug : if email address is:[email protected] [email protected] or [email protected]. You cant use /[\w.]+\[email protected]\w+.(com|com.)/g; . It only works if you use: /[\w.]+\[email protected]\w+.(com.|com)/g; i dont know why i put "com." before “com” (com.|com) then it works
i tested on that site, and dont know why put (com.|com), it’ll work. But (com|com.) its not match
Huh? Neither order does what you want it to do. The reason they work differently is because the conditional logic looks for what’s before the
| first, then what’s after it (think of it like
Depends exactly how you’ll be using this, but you probably want to be searching entire strings, in which case you should start with
^ and end with
$. Then you won’t have this problem, because the string either matches or it doesn’t (no partial matches allowed).
So you then might have something like this:
Thank you for your great explanation, but your regex still need to be this /[\w.]+\[email protected]\w+.(com.(ru|cn)|com)/ in order to work
Amended post above to include
If you want to get that to work on regexr while checking multiple strings, you also need to set the multiline tag and put each string you want to test on a different line.
I think it shows no matches because your sample text spans multiple lines. Try adding the multiline flag.
. matches any character except a newline, so
[email protected] will match. You should use
\. instead (except when inside a pair of
Try this one:
thanks alot for your reply, your code works !
The dot means “anything” if it’s not escaped (and it’s greedy, so it’ll try to match as many characters as possible), only if you put . does it match a simple “dot”