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

Claude Pache claude.pache at
Thu May 19 15:21:19 UTC 2016


Given a RegExp object `rx` and a string `f` that contains legal RegExp flag characters, should ideally the following expressions

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`.


More information about the es-discuss mailing list