sed to python: replace Q

Lutz Horn lutz.georg.horn at
Wed Apr 30 08:37:18 CEST 2008


2008/4/30 Raymond <not-for-mail at>:
> For some reason I'm unable to grok Python's string.replace() function.

replace() does not work with regular expressions.

>  Is there a decent description of string.replace() somewhere?

Use re.sub().

>>> import re
>>> line = "date process text [ip] more text"
>>> re.sub('].*$', '', re.sub('^.*\[', '', line, 1))


More information about the Python-list mailing list