From: Neil Conway Date: 2001-01-31T05:50:10+09:00 Subject: [ruby-talk:10137] Easy regex question Hi all, I just learned Ruby recently (coming from Perl/Java/Python), and I've got a simple question about regular expressions that I just can't seem to work out. I'm trying to SQL quote a string (for now, just replacing all single-quotes with backslash-single-quote - i.e. ' -> \'). In Perl, the following works fine: $ perl $str = "it's me"; $str =~ s/'/\\'/g; print "$str\n"; it\'s me In Ruby (Jan 18 snapshot), I get this: $ irb irb(main):001:0> str = "it's me" "it's me" irb(main):002:0> str.gsub(/'/, "\\'") "its mes me" Can someone tell me: 1) What Ruby is doing? I can't figure out what it's doing to go from "it's me" -> "its mes me" 2) The correct regex to do what I'm looking for Thanks, and sorry for asking dumb questions ;-) I think I've been coding in Java for too long, my brain is going to mush! Cheers, Neil -- Neil Conway Get my GnuPG key from: http://klamath.dyndns.org/mykey.asc Encrypted mail welcomed Great spirits have always encountered violent opposition from mediocre minds. -- Albert Einstein