Over a million developers have joined DZone.

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;

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}