In the grammar I am developing with PLY, I find it more useful to have readable regular expressions instead of optimal ones. So I asked on comp.lang.python about how to create an alternating regular expression:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/1023b91e232b0a53/d8d33e8287ff9806?lnk=gst&q=metaperl+expression#d8d33e8287ff9806 I developed the following code: import re def oneOf(s): alts = sorted(s.split(), reverse=True) alts = [re.escape(s) for s in alts] return "|".join(alts) And am happy with the improved readability of my tokenizing expressions: t_VOWEL = r'(?:a[aiu]?|ii?|uu?|\.(?:rr?|ll?)|[eo])' t_VOWEL = oneOf('a aa i ii u uu .r .R .l .L e ai o au') And am willing to take the speed hit. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ply-hack" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/ply-hack?hl=en -~----------~----~----~----~------~----~------~--~---
