Expanding regexps

Fredrik Lundh fredrik at pythonware.com
Tue Oct 28 15:58:37 EST 2003


Klaus Alexander Seistrup wrote:

> Is there a way to "expand" simple regexps?  Something along the
> lines of:
>
> #v+
>
> >>> rx = '(a|b)c?(d|f)'
> >>> expand_regexp(rx)
> ['ad', 'af', 'acd', 'acf', 'bd', 'bf', 'bcd', 'bcf']
> >>>
>
> #v-

hint:

    import sre_parse
    print sre_parse.parse(rx)

the rest is just a small matter of programming.

</F>








More information about the Python-list mailing list