Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore other solutions #38

Closed
bergus opened this issue Jul 31, 2015 · 7 comments
Closed

Explore other solutions #38

bergus opened this issue Jul 31, 2015 · 7 comments

Comments

@bergus
Copy link
Contributor

bergus commented Jul 31, 2015

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, Alternate proposal: RegExp.fromString #33, with regex combinators as RegExp.prototype methods, to provide a fluent interface for regex construction/combination
  • RegExp.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?

@bergus
Copy link
Contributor Author

bergus commented Jul 31, 2015

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
Copy link
Collaborator

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

@bergus
Copy link
Contributor Author

bergus commented Jul 31, 2015

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")

@bergus bergus changed the title investigate other solutions Explore other solutions Jul 31, 2015
@ljharb
Copy link
Member

ljharb commented Aug 1, 2015

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
Copy link

erights commented Aug 11, 2015

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
Copy link
Contributor Author

bergus commented Aug 12, 2015

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

@bergus bergus closed this as completed Aug 12, 2015
@benjamingr
Copy link
Collaborator

@erights that proposal looks abandoned, status?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants