我想在VB中用正则表达式来提取字符串中的email地址。从网上搜了这么一段代码,但是运行失败。错误在这一句set mh = mhs(0)
完整的代码如下
Dim reg As RegExp
Dim mh As Match
Dim mhs As MatchCollection
Dim inpStr As String
inpStr = "[email protected]"
Set reg = New RegExp
reg.IgnoreCase = True
reg.Global = True
reg.Pattern = "(w+)@(w+).(w+)"
Set mhs = reg.Execute(inpStr)
If IsNull(mhs) Then
MsgBox "mhs is null"
End If
Dim index As Long
index = 0
Set mh = mhs(index) ' run-time error 5 invalid procedure call or argument *****出错啦******
Debug.Print "电子邮件地址是: " & mh.Value '这里是匹配的内容
Debug.Print "用户名是: " & mh.SubMatches(0) '第一个括号中的内容
Debug.Print "邮箱是: " & mh.SubMatches(1) '第二个括号中的内容
Debug.Print "域名是: " & mh.SubMatches(2) '第三个括号中的内容
------解决方案--------------------
好像发错版块了。。。。
------解决方案--------------------
嗯....
这是PB ,不是VB 哦.
------解决方案--------------------
发错地方了.........
------解决方案--------------------
这个想当初我也把pb听成了vb~~~
------解决方案--------------------
Set mh = mhs(index).value
------解决方案--------------------
------解决方案--------------------
原来是发错地方的
回复内容太短了!