如果电子邮件始终包含在最后的<> 中,您可以
Public Function fmt(email As String) As String
pos = InStrRev(email, "<")
If (pos > 0) Then
email = Mid$(email, 1 + pos, 1 + Len(email) - pos)
email = Left$(email, Len(email) - 1)
End If
fmt = email
End Function
或
replace(mid(email,instrrev(email,"<")+1,len(email)),">","")
编辑;
对于正则表达式检查,添加对“Microsoft VBScript 正则表达式库”的引用(工具 > 引用)和;
Public Function fmt(email As String) As String
pos = InStrRev(email, "<")
If (pos > 0) Then
email = Mid$(email, 1 + pos, 1 + Len(email) - pos)
email = Left$(email, Len(email) - 1)
End If
fmt = email
With New RegExp
.Global = True
.IgnoreCase = True
.MultiLine = True
.Pattern = "^\S+@\S+\.\S+$"
If Not .Test(fmt) Then fmt = ""
End With
End Function
这将返回一个有效的电子邮件地址,如果它无效,则返回“”。
我放弃了你的 RE;推理:Using a regular expression to validate an email address