VB基礎(chǔ):VB6通過正則表達(dá)式定位字符串

字號:

VB6 通過正則表達(dá)式定位字符串的實(shí)現(xiàn)方法如下:
    [工程]-[引用] \"Microsoft VBScript Regular Expressions\"
    ’本例是要定位字符串s中數(shù)字出現(xiàn)的位置
    Private Sub Command1_Click()
    Dim re As RegExp, s As String, Matchs
    s = \"http://blog.sina.com.cn/juyonghong/123456.html\"
    Set re = New RegExp
    re.Pattern = \"\\d+\" ’數(shù)字序列
    If re.Test(s) Then ’測試是否存在
    Set Matchs = re.Execute(s)
    Print Matchs(0).FirstIndex ’顯示位置
    End If
    End Sub