To support more forms of e-mails, try this pattern (in VB):
"([\p{L}\p{N}_\-\.]+)@([\p{L}\p{N}_\-]+[\.\u3002\uFF0E\uFF61])+([\p{L}\p{N}_\-]+)"
If it does not always work, show examples.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello
I'm using this to collect emails from string:
Dim mc As MatchCollection = Regex.Matches(src, "([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,9})", RegexOptions.CultureInvariant Or RegexOptions.IgnoreCase Or RegexOptions.Multiline)
This will not work on Idn domains, however, there's a validator sample here:
How can I get regex matches and assign to MatchCollection for Idm domains using the above mentioned regex which is:
"^[^@\s]+@[^@\s]+\.[^@\s]+$"
Thanks :)
To support more forms of e-mails, try this pattern (in VB):
"([\p{L}\p{N}_\-\.]+)@([\p{L}\p{N}_\-]+[\.\u3002\uFF0E\uFF61])+([\p{L}\p{N}_\-]+)"
If it does not always work, show examples.
To match email addresses that include Internationalized Domain Names (IDNs), you can use a more comprehensive regular expression. The regex you mentioned (^[^@\s]+@[^@\s]+\.[^@\s]+$
) is a good start, but it doesn’t cover all the nuances of IDNs.
Here’s an updated version of your code to handle IDNs:
Dim mc As MatchCollection = Regex.Matches(src, "^[^\s@]+@[^\s@]+\.[^\s@]+$", RegexOptions.CultureInvariant Or RegexOptions.IgnoreCase Or RegexOptions.Multiline)
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
there is no 100% accurate regex for email. see this
https://fightingforalostcause.net/content/misc/2006/compare-email-regex.php
or this generated one::