I'm not as sure about `eval`, but absolutely `new RegExp(rx.source, rx.flags)` should always imo reproduce a functionally equivalent regex.
On Thu, May 19, 2016 at 8:21 AM, Claude Pache <claude.pa...@gmail.com> wrote: > Hi, > > Given a RegExp object `rx` and a string `f` that contains legal RegExp > flag characters, should ideally the following expressions > > ```js > RegExp(rx, f) > eval("/" + rx.source + "/" + f) > ``` > > always return a functional regexp? > > Practical example: `rx = /\-/`, and `f === "u"` (recall that `\-` is > invalid in u-regexps but valid in non-u-regexps). > > One may wish that `RegExp(/\-/, "u")` and `eval("/" + /\-/.source + "/u")` > be both equivalent to `/-/u`. > > Context: That question came up while I was thinking about a possible > precise specification for `RegExp.prototype.source`. > > —Claude > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss