From: Daniel DeLorme Date: 2007-08-08T08:35:45+09:00 Subject: Re: Alternate Regular Expressions? Kenneth McDonald wrote: > Speaking as someone who has actually written and used (in Python) a more > abstract regex library, > the biggest problem with regular expressions in most languages isn't the > syntax, but rather > the inability to easily compose small REs into larger REs. Which is why > so many programs end > up with huge, unreadable REs. As a small example, it's really nice (and > obvious) to be able to say > > re3 = re1 + re2 I agree with this and that's why I have the following add-on in my standard lib: class Regexp def +(other) if other.is_a?(Regexp) if self.options == other.options Regexp.new(source + other.source, options) else Regexp.new(source + other.to_s, options) end else Regexp.new(source + Regexp.escape(other.to_s), options) end end end It could easily be improved so that, for example, a range would get appended as a character class, etc. Daniel