[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Regexp#match(str, *offset*

nobu.nokada

9/30/2004 4:01:00 AM

Hi,

At Thu, 23 Sep 2004 18:16:50 +0900,
trans. (T. Onoma) wrote in [ruby-talk:113491]:
> Curious, where's the offset? I can do this with String#index:
>
> str.index(/re/,offset)
> $~.begin
> $~.end
>
> But not with Regexp itself?

$ ruby19 -ve 'p(/\s/.match(" abc def", 0).begin(0))'
ruby 1.9.0 (2004-09-29) [i686-linux]
1
$ ruby19 -ve 'p(/\s/.match(" abc def", 1).begin(0))'
ruby 1.9.0 (2004-09-29) [i686-linux]
4

--
Nobu Nakada


1 Answer

Simon Strandgaard

9/30/2004 4:23:00 PM

0

On Thursday 30 September 2004 06:01, nobu.nokada@softhome.net wrote:
> At Thu, 23 Sep 2004 18:16:50 +0900,
> trans. (T. Onoma) wrote in [ruby-talk:113491]:
> > Curious, where's the offset? I can do this with String#index:
> >
> > str.index(/re/,offset)
> > $~.begin
> > $~.end
> >
> > But not with Regexp itself?
>
> $ ruby19 -ve 'p(/\s/.match(" abc def", 0).begin(0))'
> ruby 1.9.0 (2004-09-29) [i686-linux]
> 1
> $ ruby19 -ve 'p(/\s/.match(" abc def", 1).begin(0))'
> ruby 1.9.0 (2004-09-29) [i686-linux]
> 4

Wonderful Nobu.. This is a feature I always have needed without knowing it.

Thanks.

--
Simon Strandgaard