From: Matt Date: 2008-05-18T14:50:13+09:00 Subject: Re: sub/gsub bug? Phlip wrote: > Untill someone dissects the source and finds (or adds) a better fix, here's > a workaround: Thanks for the reply, Phlip. As it turns out, when I was researching this problem I found out that you can use replaceable parameters in DBI queries instead of worrying about escaping quotes, so that's a relief. I was just kind of curious why gsub() wasn't working the way I thought it would. > irb(main):012:0> "matt's test".sub(/'/){"\\'"} > => "matt\\'s test" > > That surprised me too, because I thought that sub's block form also > interpolated \n group inserters, but I suppose that blocks have room for > true $1 match references. \1 is often available in some regular expressions > that cram all the searchers and replacers into one huge line, so a $1 is > naturally not available inside its own source expression. (I also don't > happen to know if Ruby supports such super-regices!) Yeah that's strange that they would write two replacement string parsers, but I guess there's probably a good reason for it. Super-regices? You mean like s/xxx/yyy/g? I haven't seen that anywhere in my Ruby travels, but I'm kind of new. Matt