1
如何从VBA中的电子邮件地址提取用户名?Outlook VBA正则表达式提取电子邮件地址中的用户名
例如 - 如果我的电子邮件ID是 “[email protected]”,那么用户名是 “prateek”
到目前为止 - 我写了这一点 -
Set Reg1 = New RegExp
' \s* = invisible spaces
' \d* = match digits
' \w* = match alphanumeric
With Reg1
.Pattern = "\[email protected]\.com"
.Global = True
End With
If Reg1.Test(emailAddress) Then
Set M1 = Reg1.Execute(emailAddress)
For Each M In M1
' M.SubMatches(1) is the (\w*) in the pattern
' use M.SubMatches(2) for the second one if you have two (\w*)
Debug.Print M.SubMatches(1)
Next
End If
但它并不像它去任何submatch
正则表达式是没有必要在这里,你可以使用左,与InStr函数寻找@ –
@ShaiRado:哎呀,我打字^^ – R3uK