splitting perl-style find/replace regexp using python

Peter Otten __peter__ at web.de
Thu Mar 1 06:10:09 EST 2007


John Pye wrote:

> Is there an easy and general way that I can split these perl-style
> find-and-replace expressions into something I can use with Python, eg
> re.sub('search','replace',str) ?

Another candidate:

>>> re.compile(r"(?:/((?:\\.|[^/])*))").findall(r"/abc\\/def\/ghi//jkl")
['abc\\\\', 'def\\/ghi', '', 'jkl']

Peter



More information about the Python-list mailing list