Regular expressions and sub

Emhoff thehofffs at hotmail.com
Thu Mar 25 21:44:43 EST 2004


Hey hey --

I've got a question about regular expression substitions.  Basically,
I want to do something like this:

re.sub(r"(stuff)|(blah)", r"I was \00", "stuff blah")

Which would yield the string "I was stuff I was blah" -- but I get "I
was \x00 I was \x00" because apparently the replace string is simply
being interpreted as a normal string, and not a regular expression.

So, my question is, is there a simple way to do what I want?

Thanks much,
John



More information about the Python-list mailing list