From: Axel Etzold Date: 2007-11-26T01:46:39+09:00 Subject: Re: [Q] specify start postion of Regexp matching -------- Original-Nachricht -------- > Datum: Mon, 26 Nov 2007 00:20:25 +0900 > Von: makoto kuwata > An: ruby-talk@ruby-lang.org > Betreff: [Q] specify start postion of Regexp matching > Hi, all. > > Is it possible to specify start position of Regexp matching? > > str = "foo bar baz" > m = /ba/.match(str) > p m.begin(0) #=> 4 > m = /ba/.match(str, 5) # is it possible? > p m.begin(0) #=> 8 (if possible) > > If it is possible, some kind of parser or scanner can be > implemented easily. > # StringScanner is a litte too big, I think. > > -- > makoto kuwata > Dear Makoto, what about : class Regexp def match_index_offset(string,start_pos) temp=string[start_pos..-1] ref=self.match(temp) return temp.index(ref[0])+start_pos end end str = "foo bar baz" m = /ba/.match_index_offset(str,5) p m Best regards, Axel -- Psssst! Schon vom neuen GMX MultiMessenger geh�rt? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger