RegEx

James Kew james.kew at btinternet.com
Thu May 16 03:26:48 EDT 2002


"x" <jar at mminternet.com> wrote in message
news:MPG.174a3c3e60a4607b98969a at news.mminternet.com...
>         no_parans = re.compile('(|)', count = 99)
>         scan_line = no_parans.sub(' ', scan_line)

As an aside, that count=99 argument to re.compile does nothing. sub does
take an optional count argument, but if omitted or zero sub replaces all
occurrences.

I quite like John's suggestion of a '[()]' regex as it makes it clearer that
you are replacing characters.

Or build a translation table:

trans = string.maketrans('()', '  ')
scan_line = scan_line.translate(trans)

which would make it easier to add new character substitutions later should
you need to.

--
James Kew






More information about the Python-list mailing list