RegEx: Grabbing values between quotation marks

前端 未结 20 1229
暖寄归人
暖寄归人 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

    In general, the following regular expression fragment is what you are looking for:

    "(.*?)"
    

    This uses the non-greedy *? operator to capture everything up to but not including the next double quote. Then, you use a language-specific mechanism to extract the matched text.

    In Python, you could do:

    >>> import re
    >>> string = '"Foo Bar" "Another Value"'
    >>> print re.findall(r'"(.*?)"', string)
    ['Foo Bar', 'Another Value']
    

提交回复
热议问题