By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,766 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,766 IT Pros & Developers. It's quick & easy.

Regular expressions and sub

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Thu, 2004-03-25 at 21:44, Emhoff wrote:
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


Here's one way:
re.sub(r"(stuff|blah)", r"I was \1", "stuff blah")

'I was stuff I was blah'

Rich
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.