RegEx

Thomas Guettler zopestoller at thomas-guettler.de
Tue May 14 11:17:25 EDT 2002


x wrote:

> I have a quick regular expression question.
> 
> I'm trying to substute all parathesis -- both left and right -- with a 
> space.  I've tried:
> 
>         no_parans = re.compile('(|)', count = 99)
> 
>         scan_line = no_parans.sub(' ', scan_line)
> 
> 
> This doesn't work.  It had the effect of inserting a space before every 
> character, including the paranthesis.
> 
> What is the solution?


Parenthesis are special in regular expressions. They are used
for grouping. Use re.compile(r'\(|\)', ...) to match paranthesis.


thomas




More information about the Python-list mailing list