RegEx: Grabbing values between quotation marks

前端 未结 20 1770
暖寄归人
暖寄归人 2020-11-22 02:13

I have a value like this:

\"Foo Bar\" \"Another Value\" something else

What regex will return the

20条回答
  •  天命终不由人
    2020-11-22 02:55

    A supplementary answer for the subset of Microsoft VBA coders only one uses the library Microsoft VBScript Regular Expressions 5.5 and this gives the following code

    Sub TestRegularExpression()
    
        Dim oRE As VBScript_RegExp_55.RegExp    '* Tools->References: Microsoft VBScript Regular Expressions 5.5
        Set oRE = New VBScript_RegExp_55.RegExp
    
        oRE.Pattern = """([^""]*)"""
    
    
        oRE.Global = True
    
        Dim sTest As String
        sTest = """Foo Bar"" ""Another Value"" something else"
    
        Debug.Assert oRE.test(sTest)
    
        Dim oMatchCol As VBScript_RegExp_55.MatchCollection
        Set oMatchCol = oRE.Execute(sTest)
        Debug.Assert oMatchCol.Count = 2
    
        Dim oMatch As Match
        For Each oMatch In oMatchCol
            Debug.Print oMatch.SubMatches(0)
    
        Next oMatch
    
    End Sub
    

提交回复
热议问题