Should RegExp(regexp, flags) always return a functional RegExp for reasonable values of flags?

Jordan Harband ljharb at gmail.com
Thu May 19 15:54:08 UTC 2016


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.pache at 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 at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160519/84827fd1/attachment.html>


More information about the es-discuss mailing list