asp正则表达式中 Match的SubMatches属性

[ 2010-05-24 22:12:43 | 作者: admin ]
字号: | |
Private Sub Command3_Click()

        Dim re As RegExp
        Dim mh As Match
        Dim mhs As MatchCollection
        Dim inpStr As String
       
          inpStr = "我的E-mail: ***@gmail.com ,欢迎来函!"
        Set re = New RegExp
          re.Pattern = "(w+)@(w+).(w+)" ‘需要用小括号来分组,否则SubMatches无法使用
        Set mhs = re.Execute(inpStr)
        Set mh = mhs(0) '只有一个匹配
       
          Debug.Print "电子邮件地址是: " & mh.Value '这里是匹配的全部内容
          Debug.Print "用户名是: " & mh.SubMatches(0) '第一个括号中的内容
          Debug.Print "邮箱是: " & mh.SubMatches(1) '第二个括号中的内容
          Debug.Print "域名是:   " & mh.SubMatches(2) '第三个括号中的内容
       
End Sub
[最后修改由 admin, 于 2010-08-11 20:44:31]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1402

这篇日志没有评论。

此日志不可发表评论。