Seeking regex optimizer

John Machin sjmachin at lexicon.net
Mon Jun 19 08:56:32 EDT 2006


On 19/06/2006 7:06 PM, Kay Schluehr wrote:
> Mirco,
> 
> with "special characters" I mentioned control characters of regular
> expressions i.e. one of ".^$()?[]{}\|+*" but not non ascii-127
> characters.
> 
> For a workaround you simply have to "mangle" those using an escape
> control character:
> 
> REGEXCHAR = ".^$()?[]{}\\|+*"
> def mangle(s):
>     pattern = []
>     for c in s:
>         if c in REGEXCHAR:
>             pattern.append("\\")
>         pattern.append(c)
>    return "".join(pattern)
>  

What's wrong with re.escape()?
Have you not read (a) my response to Paddy's first posting (b) the manual?





More information about the Python-list mailing list