tc39 / proposal-regex-escaping

Proposal for investigating RegExp escaping for the ECMAScript standard
http://tc39.es/proposal-regex-escaping/
Creative Commons Zero v1.0 Universal
363 stars 32 forks source link

Explore other solutions #38

Closed bergus closed 9 years ago

bergus commented 9 years ago

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?

Both do have a problem with flags though, which are difficult to express. Is there anything else?

bergus commented 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.

benjamingr commented 9 years ago

RegExp.escaped but I don't feel like a tag is the "right" way to go forward yet.

bergus commented 9 years ago

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")
ljharb commented 9 years ago

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)

erights commented 9 years ago

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!

bergus commented 9 years ago

@erights A new repository seems suited for discussion of this particular approach. As you can see, I've just opened 6 issues there :-)

benjamingr commented 8 years ago

@erights that proposal looks abandoned, status?