From: Robert Klemme Date: 2010-11-08T19:38:28+09:00 Subject: [ruby-core:33104] Re: Suggestion for MatchData#first and #last On Mon, Nov 8, 2010 at 10:04 AM, NARUSE, Yui wrote: > 2010/11/8 Robert Klemme : >> On Mon, Nov 8, 2010 at 9:34 AM, NARUSE, Yui wrote: >>> 2010/11/8 Robert Klemme : >>>> Btw, I just notice this >>>> >>>> irb(main):016:0> /(?fo+).*(\g)/ =~ "foooobarfoo" >>>> => 0 >>>> irb(main):017:0> $1 >>>> => "foo" >>>> irb(main):018:0> $2 >>>> => nil >>>> irb(main):019:0> f >>>> => "foo" >>>> irb(main):020:0> RUBY_VERSION >>>> => "1.9.1" >>>> irb(main):021:0> RUBY_PATCHLEVEL >>>> => 429 >>>> >>>> I thought named group would have the same capturing semantics as >>>> unnamed groups but apparently the leading named group is not >>>> considered as capturing. �Is the behavior shown above intended? >>> >>> When you use named capture, you can't use normal parentheses. >>> It becomes (? .. ). >> >> I think this is not true, because as long as I do not use \g I can >> access the group via name *and* via index: >> >> irb(main):004:0> /(?fo+)/ =~ "foobar" >> => 0 >> irb(main):005:0> $1 >> => "foo" >> irb(main):006:0> a >> => "foo" >> >> That's also in line with what the doc says >> http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt >> >> Or did you mean "when using *calls* to named captures"? �Because >> that's where the difference comes in. > > I mean, in RE.txt's words, named group. > When you use named group, (?...), in a regexp, > (...) in the regexp is treated as (?...). Ah, you mean that a single named group makes all "regular" groups loose their capturing feature and behave like non capturing groups. Thanks! Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/