re.split question
Cliff Crawford
cjc26 at nospam.cornell.edu
Thu Jun 22 23:27:41 EDT 2000
* Steffen Ries <steffen.ries at sympatico.ca> menulis:
|
| Unfortunately, this does not do what I need:
| >>> t='uid=joe, ou=orgunit, o=some\\, org'
| >>> pat.split(t)
| ['uid=joe', ' ou=orgunit', ' o=some\\', ' org']
You could use string.replace to change the \, sequence into a sequence
that won't appear in your input, then split on ,. For example, if you
know that you'll never get any strings with "\@" in it, then you
could do:
t = 'uid=joe, ou=orgunit, o=some\\, org'
t1 = string.replace(t, r'\,', r'\@')
l = string.split(t1, ',')
l1 = map(lambda str: string.replace(str, r'\@', r'\,'), l)
(the last line goes through and changes "\@" back to "\,")
--
cliff crawford -><- http://www.people.cornell.edu/pages/cjc26/
Synaesthesia now! icq 68165166
More information about the Python-list
mailing list