----- Original Message -----
From: Mathieu Bouchard <matju / sympatico.ca>
To: ruby-talk ML <ruby-talk / ruby-lang.org>; Tobias Reif
<tobiasreif / pinkjuice.com>
Cc: ruby-talk ML <ruby-talk / ruby-lang.org>
Sent: Monday, November 05, 2001 9:33 AM
Subject: [ruby-talk:24395] Re: Joys of eval


> What I've come up with in Ruby ended up to be a bit different:
>
> class Regexp
>       def to_s
>               x=inspect
>               x[1,x.length-2]
>       end
>       def +(b); Regexp.new "#{a}#{b}"; end
>       def -(b); Regexp.new "(?!#{b})#{self}"; end
>       def &(b); Regexp.new "(?=#{b})#{self}"; end
>       def |(b); Regexp.new "(?:#{self}|#{b})"; end
>       def *(n); Regexp.new "(?:#{self}){#{n},#{n}}"; end
> end
>
> Which allows some infix arithmetic on regexps, respectively: sequence,
> negative lookahead, positive lookahead, alternative, fixed repetition.
>

That's very interesting. I had been thinking about
some ways to enhance regexes, but this is a new
technique to me.

Do you have examples of using these?

Hal