convert list of strings to set of regexes; convert list of strings to trie
François Pinard
pinard at iro.umontreal.ca
Mon Jul 19 11:16:22 EDT 2004
[Klaus Neuner]
> I need a function that converts a list into a set of regexes. Like so:
> string_list = ["blaa", "blab", "raaa", "rabb"]
> print string_list2regexes(string_list)
> This should return something like:
> ["bla(a|b)", "ra(aa|bb)"]
I once wrote code for doing something very close, but not finding it,
I guess I deleted it; so presumably, it would not be that difficult
redoing from scratch. By the way, the regexp compiler in Python library
already turns, at least logically, `(blaa)|(blab)|(raaa)|(rabb)' into
`(bla(a|b))|(ra(aa|bb))' -- disregarding of course how groups are being
saved by parentheses. So, you may also peek in this direction.
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list