> I need replace backslashes with double backslashes.
Try this:
[% text.replace('\\\\', '\\\\') %]
It doesn't look right, but it is.
First remember that to get a single backslash, you need to escape it inside
single and double quotes.
[% text = 'here\\is\\the\\news' %] # here\is\the\news
Then you need to remember that '\' must be escaped again inside a regex.
In Perl it would be like this:
my $bs = '\\';
my $qm = quotemeta($bs);
$text =~ s/$qm/$bs$bs/;
| |
V V
'\\\\' '\\\\'
In TT the first argument to replace() is a regex, and so all backslashes
must be escaped twice (once for the quoting, once for the regex). The
second argument is a replacement string, so backslashes only need to be
escaped once.
[% text.replace(regex, string) %]
\ \\ Original characters
'\\' '\\\\' Escaped for quotes
qr/\\\\/ '\\\\' Escaped again for regex (1st arg only)
HTH
A
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates