string.split escaping

Andrew Bennetts andrew-pythonlist at puzzling.org
Thu May 29 02:39:27 EDT 2003


On Thu, May 29, 2003 at 04:17:42PM +1000, Dave Harrison wrote:
> Ok I should probably change the post a little ...
> 
> My intention (as the subject suggested) was to find a way of escaping the
> split value.
> 
> This means I want to be able to ignore my split character at any part of
> the string ... not just at the end, so maxsplit isnt what Im after.

There's no way to escape characters from str.split.  You probably need to
resort to the re module -- try re.split, and "negative look-behind
assertions", e.g.

>>> re.split(r'(?<!\\);', 'abc;def\;ghi')
['abc', 'def\\;ghi']

-Andrew.






More information about the Python-list mailing list