From: 7stud 7stud Date: 2007-03-14T17:35:45+09:00 Subject: Re: ruby regex lookarounds? > Isn't that output inconsistent? If Ruby wants to say that the regex > matches the whole string, then shouldn't $1 be 'ab'. I know that > lookarounds shouldn't be considered part of the match--they are just > assertions, but Ruby's $& variable doesn't seem to respect that. I see what's going on. (?:ab) is not a grouping: (?: and ) do not form a grouping that gets a $ variable. If I write it as (?:(ab)), then ab is a grouping: irb(main):021:0> "abc" =~ /(?:(ab))(c)/ => 0 irb(main):022:0> $& => "abc" irb(main):023:0> $1 => "ab" irb(main):024:0> $2 => "c" irb(main):025:0> It still seems a little strange that $& contains the lookaround. -- Posted via http://www.ruby-forum.com/.