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;
12374 users tagging and storing useful source code snippets
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
s = "12345" puts s.gsub(/(2|4)/, '\\\\\1')
$s="12345"; print preg_replace("/(2|4)/", '\\\\\1', $s);
$s="123456"; $s =~ s/(2|4)/\\\1x/g; print $s;
You need to create an account or log in to post comments to this site.