如何在vb6中使用正则表达式提取文本

时间:2010-12-23 07:09:34

标签: regex vb6

如何在vb6中使用正则表达式提取文本

Dim MyText As String

MyText = "anything [*]textToExtract[*] anything"

结果应该是:

textToExtract

1 个答案:

答案 0 :(得分:3)

Sub test()
    Dim re As RegExp, m As MatchCollection
    Set re = New RegExp
    Dim MyText As String, extractedText As String
    MyText = "anything textToExtract anything"

    re.Pattern = "anything (.*) anything"
    Set m = re.Execute(MyText)
    extractedText = m(0).SubMatches(0)

End Sub