Dave wrote: I'm still not entirely clear what you're expecting to see and what you think is wrong.
However, the first argument to the replace vmethod is a regex. And a ? character has a special meaning in a regex. If you want a ? to be seen as a "real" ? in a regex then you'll need to escape it (with a backslash). Either use the (Perl) quotemeta function, or the \Q ... \E escapes in your regex. Dave... > Message: 1 > Date: Wed, 17 Feb 2010 14:00:46 +0100 > From: Tosh Cooey <[email protected]> > Subject: Re: [Templates] .replace(ing) ? > To: [email protected], [email protected] > Message-ID: <[email protected]> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Sorry Chad you're right, that was a working example, try this: > > dev:~# tpage > output > > [% link = 'http://site.com?oops' %] > [% linkText = 'http://site.com?oops' %] > [% ahref = '<a href="' _ link _ '">' _ linkText _ '</a>' %] > [% bodyText = "Some text waiting for link insertion, > http://site.com?oops" %] > > [% bodyText.replace(linkText, ahref) %] > > > dev:~# cat output > Some text waiting for link insertion, http://site.com?oops > > Tosh > I'm expecting to see: Some text waiting for link insertion, <a href= "http://site.com?oops">http://site.com?oops</a> This is the first time in my years using TT that I have actually come across this problem. Is it not possible to tell the replace function to not interpret the first arg as a regex? I can't imagine I'm the only person who has ever wanted to replace characters like ? or whatever else will get caught there. I just want to replace strings, is there another function for that with no restrictions on the strings? Tosh -- McIntosh Cooey - Twelve Hundred Group LLC - http://www.1200group.com/ _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates
