DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Escape A Character With Backslashes
Ruby:
s = "12345" puts s.gsub(/(2|4)/, '\\\\\1')
PHP:
$s="12345";
print preg_replace("/(2|4)/", '\\\\\1', $s);
Perl:
$s="123456"; $s =~ s/(2|4)/\\\1x/g; print $s;




