lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Yes


On Fri, Aug 22, 2014 at 4:25 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> >
> > 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