re.sub question (regular expressions)

Chris Seberino cseberino at gmail.com
Fri Oct 16 12:20:42 EDT 2009


What does this line do?...

input_ = re.sub("([a-zA-Z]+)", '"\\1"', input_)

Does it remove parentheses from words?
e.g. (foo) -> foo ???

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?

cs



More information about the Python-list mailing list