re.sub question (regular expressions)

MRAB python at mrabarnett.plus.com
Fri Oct 16 12:51:24 EDT 2009


Chris Seberino wrote:
> What does this line do?...
> 
> input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_)
> 
Why don't you try it?

> Does it remove parentheses from words?
> e.g. (foo) -> foo ???
> 
No, it puts quotes around them.

> I'd like to replace [a-zA-Z] with \w but \w makes it blow up.
> 
> In other words, re.sub("(\w+)", '"\\1"', input_) blows up.
> 
> Why?
> 
What do you mean "blow up"? It worked for me in Python v2.6.2.



More information about the Python-list mailing list