From: Heesob Park Date: 2009-04-29T22:29:04+09:00 Subject: Re: Issue with regexp pattern matcher withing String#gsub 2009/4/29 Brian Candler : > Heesob Park wrote: >> 2009/4/29 Craig Jolicoeur : >>> ## to >>> ##  from (irb):84 >>> >>> html_string.gsub!( /src=(["'])\S+\?\d*\1/ ) { |s| s.split('?').first + >>> $1 } >>> >>> ## the question is why can I do string concat with + $1 in the first >>> regexp and >>> ## why am I unable to do it in the second regexp where doing str + $1 >>> throws the error?? >> The side effect of String#split is changing the value of $1. > > It doesn't in ruby 1.8.6: > > irb(main):007:0> /(.)/ =~ "abc"; puts $1; "a b".split(" "); puts $1 > a > a > => nil > > It will if the split is done on a Regexp (but the OP wasn't doing that) > > irb(main):008:0> /(.)/ =~ "abc"; puts $1; "a b".split(/ /); puts $1 > a > nil > => nil It does in ruby 1.8.6 irb(main):007:0> /(.)/ =~ "abc"; puts $1; "a?b".split("?"); puts $1 a nil => nil Regards, Park Heesob