Closed bergus closed 9 years ago
The first thing to do is probably to find a reasonable name for RegExp.tag
(tag
is horrible) before it settles in our minds.
RegExp.escaped
but I don't feel like a tag is the "right" way to go forward yet.
Oh, and judging from the discussion in #37 there seems to be confusion on what such a tagging function would return. Everyone seems to expect a string (that needs to be passed into the RegExp
constructor then), but I would propose it to return a regex instance? Or maybe a function that takes the flags as an argument, so that we could write something like
RegExp.… `\s*${input}\s*` ("ig")
It should probably only return a RegExp instance, otherwise all of the same compositional problems will exist as do with escape
.
Changing the flags is trivial by wrapping in the constructor: RegExp(existingRegExp, newFlags)
I am pleased to bring https://github.com/mikesamuel/regexp-make-js to your attention. @mikesamuel and I (mostly Mike) put together this draft informal specification and prototype implementation for what the RegExp template string tag should be. We think this is a comprehensive and principled approach ready for examination and discussion. Would it be better to discuss this here on this thread, or over at https://github.com/mikesamuel/regexp-make-js ?
This prototype implementation currently uses some ES6 features that are directly implemented only on Firefox. After reading the README, I suggest reading the tests next while visiting https://rawgit.com/mikesamuel/regexp-make-js/master/test.html in a Firefox browser. I think the tests should quickly clear up most questions about what the draft spec means. Please point out any ambiguities that remain. Thanks!
@erights A new repository seems suited for discussion of this particular approach. As you can see, I've just opened 6 issues there :-)
@erights that proposal looks abandoned, status?
So, the results are in, and it seems they declined
RegExp.escape
and this is a final decision.What alternatives do we have? Of course we could just fall back on a user-land implementation (like ljharb/regexp.escape, are there others?) as mentioned, but what if we want to press on?
RegExp.fromString
, #33, with regex combinators asRegExp.prototype
methods, to provide a fluent interface for regex construction/combinationRegExp.tag
, for template strings, avoids double-escaping by accessing the.raw
template parts, and solves the problem with trailing backslashes (example)Both do have a problem with flags though, which are difficult to express. Is there anything else?