pythonstringextractquotations

Extract string from between quotations


I want to extract information from user-inputted text. Imagine I input the following:

SetVariables "a" "b" "c"

How would I extract information between the first set of quotations? Then the second? Then the third?


Solution

  • >>> import re
    >>> re.findall('"([^"]*)"', 'SetVariables "a" "b" "c" ')
    ['a', 'b', 'c']