From: Robert Dober Date: 2007-06-04T20:28:56+09:00 Subject: Re: No way of looking for a regrexp match starting from a particular point in a string? On 6/4/07, Trans wrote: > > > On Jun 4, 6:19 am, "Robert Dober" wrote: > > On 6/3/07, Kenneth McDonald wrote:> I'm probably just missing something obvious, but I haven't found a way > > > to match a regular expression against only part of a string, in > > > particular only past a certain point of a string, as a way of finding > > > successive matches. Of course, one could do a match against a string, > > > take the substring past that match and do a match against the substring, > > > and so on, to find all of the matches for the string, but that could be > > > very expensive for very large strings. > > > > > I'm aware of the String.scan method, but that doesn't work for me > > > because it doesn't return MatchData instances. > > > > > What I want is just something like regexp.match(string, n), > > > > Hmm apart of using #scan and #index with $~ as indicated, I do not > > think that there is a performance penalty if you do > > > > rg.match(string[n..-1]) > > How can that be? You have to create a whole new String. Beating a dead man Tom? As mentioned I had a terrible slip to C in my reasoning, no idea why :( > If that can be avoided in the internal implementation then adding an optional offset > index to #match is not an unreasonable idea. > > T. > > > -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw