本实例演示使用 Microsoft VBScript Regular Expressions 5.5 来搜索邮箱地址。
新建一个VB 标准EXE 工程并引用 Microsoft VBScript Regular Expressions 5.5。
代码如下:
'用户昵称: 留下些什么
'个人简介: 一个会做软件的货代
'CSDN网址:https://blog.csdn.net/zezese
'电子邮箱:31319180@qq.com
Option Explicit
Private Sub Command1_Click()
Const strTmp As String = "123456789@qq.com,这是我的邮箱,另外一个是 987654321@qq.com。"
Dim MyRegExp As RegExp
Set MyRegExp = New RegExp
MyRegExp.Global = True '匹配全部
MyRegExp.IgnoreCase = True '忽略大小写
MyRegExp.MultiLine = True ' 进行多行匹配
MyRegExp.Pattern = "[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+" '邮箱地址
Dim mc As MatchCollection, m As Match
Set mc = MyRegExp.Execute(strTmp)
For Each m In mc
Debug.Print m.Value
Next
End Sub