滚滚长江东逝水,浪花淘尽(英雄)。是非成败转头空。(青山)依旧在,几度夕阳
红。 白发渔樵江渚上,惯看秋月春风。一壶浊酒喜相逢。(古今)多少事,都付
笑谈中。我如何用一个pattern来匹配()中的词?谢谢!!!

解决方案 »

  1.   

    英雄 青山  古今就这三个词??  特殊记忆一下
    if  str= "英雄" or str="青山 " or str="古今"
      

  2.   

    pattern: "*英雄*青山*古今*"
      

  3.   

    vbman2003 :不对呀,无匹配结果!tianhuo_soft,sunday410 :抱歉,我这只是个例子,实际上要几千个在()里的词。高手帮帮忙,谢谢!!!
      

  4.   

    我在MS下载的RegexTester中测试是正常的,可VB中试了下没通过,有空时要研究下
    VB中这样可以,只是不知道符合不符合你所有情况:
    '引用 Microsoft VBScript Regular ExpressionsFunction TestRegExp(s As String, p As String) As String
       
       Dim oRegExp As RegExp
       Dim oMatch As Match
       Dim colMatches As MatchCollection
       Dim RetStr As String   Set oRegExp = New RegExp   oRegExp.Pattern = p
       oRegExp.IgnoreCase = True
       oRegExp.Global = True   If oRegExp.Test(s) Then
            Set colMatches = oRegExp.Execute(s)
            For Each oMatch In colMatches
                RetStr = RetStr & oMatch.Value & vbCrLf
            Next
        Else
            RetStr = "String Matching Failed"
        End If
        TestRegExp = RetStr
    End FunctionPrivate Sub Command1_Click()
        Dim s As String
        Dim p As String
        
        s = "滚滚长江东逝水,浪花淘尽(英雄)。" _
            & "是非成败转头空。(青山)依旧在,几度夕阳红。" _
            & "白发渔樵江渚上,惯看秋月春风。一壶浊酒喜相逢。" _
            & "(古今)多少事,都付笑谈中?"
        s = StrConv(s, vbNarrow)
        p = "\(\S{2}\)"
        Debug.Print TestRegExp(s, p)
    End Sub