http://qs321.pair.com?node_id=248270


in reply to Can this be a 1 line or simpler regex?

(fixed the code)

I suppose a single regex could be devised for this but it'd be suboptimal compared to what you already have. A short loop would also do this and again, I prefer your original.

$text =~ s/\\$r/\\\\$r/g for qw/t n r f/;
for(qw't n r f') { my $r = "\\$_"; $text =~ s/$r/$r/g; }

Replies are listed 'Best First'.
Re^2: Can this be a 1 line or simpler regex? (that doesn't work)
by Aristotle (Chancellor) on Apr 06, 2003 at 02:17 UTC
    How's that supposed to work? As is it's a no-op.

    Makeshifts last the longest.