splitting delimited strings
Leif K-Brooks
eurleif at ecritters.biz
Wed Jun 15 21:01:21 EDT 2005
Mark Harrison wrote:
> What is the best way to process a text file of delimited strings?
> I've got a file where strings are quoted with at-signs, @like this at .
> At-signs in the string are represented as doubled @@.
>>> import re
>>> _at_re = re.compile('(?<!@)@(?!@)')
>>> def split_at_line(line):
... return [field.replace('@@', '@') for field in
... _at_re.split(line)]
...
>>> split_at_line('foo at bar@@baz at qux')
['foo', 'bar at baz', 'qux']
More information about the Python-list
mailing list