From: Simon Strandgaard Date: 2004-01-03T04:31:44+09:00 Subject: Re: More questions about =~ On Fri, 02 Jan 2004 10:16:45 -0800, GGarramuno wrote: > Simon Strandgaard wrote in message news:... >> On Thu, 01 Jan 2004 12:46:54 -0800, GGarramuno wrote: >> >> >> BTW: Why are you interested in overloading the regexp methods? >> Is it because you are writing your own regexp engine? > > Kind of. > > I was just trying to have an extended string class that stored the > position of the last match position, to allow supporting something > similar to Perl's pos() command (which allows continuing matches from > the last match done or setting where to begin from like index() --- > only it works for subs and all regex methods, too). I am porting some > nasty perl code that makes heavy use of that feature. #begin /#end can tell the offset.. is that what you want ? irb(main):001:0> txt = "hello world, hello world" => "hello world, hello world" irb(main):002:0> m = /orl/.match(txt) => # irb(main):003:0> m.begin(0) => 7 irb(main):004:0> m.end(0) => 10 irb(main):005:0> > Ruby's regex > engine already has the building blocks needed to support this feature, > but the interface to it is not as easy to use as perl's. > I had thought I could use ruby's excellent OO to add this seamlessly > into the string class (and also make it work for any other string that > used my module, too). > But the fact that =~ of regex literals works in a non OO manner, has > kind of put a damp on that idea. It sound interesting, I like challenges (but i don't do perl). Can you show us some of the perl code which you are porting ? -- Simon Strandgaard