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

skip at pobox.com skip at pobox.com
Tue Sep 9 09:23:11 EDT 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:

    http://lfw.org/python/

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.

Skip




More information about the Python-list mailing list