问题
I need to confirm that the domain extension is present.
So far I have not been able to get a match for the domain extension
Where the domain name can have wild cards: gmail.com, msn.com, mac.com, comcast.net
DomainPartOfEmail = Right(temp, (Len(temp) - temp.LastIndexOf("@") - 1))
If Regex.IsMatch(DomainPartOfEmail, "*.edu? | *.com? | *.net? | *.org?", RegexOptions.IgnoreCase) Then
ValidDomain = True
End If
回答1:
If the domains are only from these(edu, com, net, org) then use this one:
".*\.(edu|com|net|org)$"
Explanation of the regex:
NODE EXPLANATION
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
edu 'edu'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
com 'com'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
net 'net'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
org 'org'
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
来源:https://stackoverflow.com/questions/22671419/regex-match-domain-extension