creating an (inefficent) alternating regular expression from a list of options

skip at skip at
Tue Sep 9 15:23:11 CEST 2008

    >> I really dont care if the expression is optimal. So the goal is
    >> something like:

    >> vowel_regexp = oneOf("a aa i ii u uu".split())  # yielding r'(aa|a|uu|
    >> u|ii|i)'

    >> Is there a public module available for this purpose?

Check Ka-Ping Yee's rxb module:

Needs translating from the old regex module to the current re module, but it
shouldn't take a lot of effort.  You can find regex docs in old
distributions (probably through 2.1 or 2.2?).  Also, check PyPI to see if
someone has already updated rxb for use with re.


More information about the Python-list mailing list