Quote-aware string splitting

George Sakkis gsakkis at rutgers.edu
Mon Apr 25 22:45:30 EDT 2005


> import re
> regex = re.compile(r'''
>                    '.*?' |  # single quoted substring
>                    ".*?" |  # double quoted substring
>                    \S+      # all the rest
>                    ''', re.VERBOSE)

Oh, and if your strings may span more than one line, replace re.VERBOSE
with re.VERBOSE | re.DOTALL.

George




More information about the Python-list mailing list