On Mon, 5 Nov 2001, Tobias Reif wrote: > > Hi, I'm somewhat of a regexp-enjoying fiend myself; but after > > Randal Schwartz posted this horrendous thing last March: > > http://www.ruby-talk.com/cgi-bin/scat.rb/ruby/ruby-talk/12815 > > I've been somewhat wary whenever someone mentions RFC822. :-) > > Instead of the obfuscated code layout of > http://www.ruby-talk.com/cgi-bin/scat.rb/ruby/ruby-talk/12815 > it's definitely better for maintenance, debugging, updtaing, > refactoring, to write complex regexen in a kinda BNF style: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65125 > > P.S. (they discussed that there in the first URL, but the output still > is a mess.) What is this email beyond simple Perl bashing? or if not Perl bashing, just a pointless mail? you say you prefer reading source code instead of compiler output??? You're comparing a *generated* regexp with a regexp *generator* and you somehow say the former is "obfuscated", but it was never meant to be hand-edited or even looked at. I haven't read the mentioned Perl book but it seems to me that the former result was generated with a program very similar to the latter program. I've already seen the regexp-interpolation trick (of the Python article) used in Perl and I've used it myself in Ruby too. 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. This could also be done in Perl 5.6 (5.5?) using qr// (which is the equivalent of Ruby's //) and operator overloading (which is the contorted equivalent of Ruby's method def with a non-alphanumeric name). I think Python is quite capable of all this stuff (except for the longish re.compile(), but it's easy to get around that, as shown in the cited example) ________________________________________________________________ Mathieu Bouchard http://hostname.2y.net/~matju