From: "NARUSE, Yui" Date: 2010-11-08T18:04:34+09:00 Subject: [ruby-core:33103] Re: Suggestion for MatchData#first and #last 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 (?...). -- NARUSE, Yui naruse@airemix.jp