[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Feature request: plain option for gsub
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 22 Aug 2014 11:25:18 -0300
> >
> > Are you aware that the example you gave (replace() in JavaScript) also
> > cannot be used on user-provided strings without escaping hassle?
> >
> > (I could not resist...)
> >
>
> Not true, at least as far as I tested ( V8 runtime ). Javascript differs
> between Strings* and RegExp objects where the literals of the second are
> written with the /bla/ syntax. When the first parameter of replace is a
> String*, replace treats it literally as well as the replacement string. I
> tested a lot with % . $ signs etc. it works all literally out of the box.
Read the specification (Ecma-262, 5.1 Edition, June 2011, page 147).
When the first parameter is a string, it treats that first parameter
literally, but it still should do substitutions in the replacement
string.
(Did you try something like "$'" in the replacement string?)
-- Roberto