From: Rob Biedenharn Date: 2009-10-27T06:52:19+09:00 Subject: Re: RCR: regex + regex On Oct 26, 2009, at 5:13 PM, Roger Pack wrote: > Feedback on the following suggestion for ruby: > by default allow for adding regex's > > i.e. >>> /foo/ + /bar/ > => /foobar/ > > Thoughts? > -r > -- irb> a=/foo/ => /foo/ irb> b=/bar/ => /bar/ irb> class Regexp irb> def +(other) irb> self.class.new(self.to_s + other.to_s) irb> end irb> end => nil irb> a+b => /(?-mix:foo)(?-mix:bar)/ This is obviously too naive an implementation, but if we change a to / foo/i then I'd expect "Foobar" =~ (a+b) to be true (well, I mean 0, of course) and "fooBar" =~ (a+b) to be nil. What might be the corresponding * or - behaviors? It seems like a * b is closer to /(a)*(b)/ than anything else I could think of and that immediately implies: a + b becomes: /(a)+(b)/ rather than just /(a)(b)/ The fact that + is a meaningful character in a Regexp makes a universal meaning for it as an operation *on* regexps a bit ambiguous. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com