Re: Re: RegExp.escape()

2017-12-05 Thread Richard Gibson
Or even better: `(?]**foo)` ("]" still terminates character classes; "**" is a less ugly normally-invalid sequence). On Tue, Dec 5, 2017 at 11:25 AM, <richard.gib...@gmail.com> wrote: > Reviving this [thread] a third time, is there any love left for > introdu

Re: Re: RegExp.escape()

2017-12-05 Thread richard . gibson
Reviving this [thread] a third time, is there any love left for introducing RegExp.escape? The previous attempt was abandoned because of a so-called "[even-odd problem]", but that can be fixed: backslash-escape every _SyntaxCharacter_, then wrap the full result in a new form of non

Re: Re: RegExp.escape()

2017-12-05 Thread richard . gibson
Reviving this [thread] a third time, is there any love left for introducing RegExp.escape? The previous attempt was abandoned because of a so-called "[even-odd problem]", but that can be fixed: backslash-escape every _SyntaxCharacter_, then wrap the full result in a new form of non-captu

Re: RegExp.escape()

2015-06-30 Thread Mathias Bynens
On Mon, Jun 29, 2015 at 9:04 PM, Benjamin Gruenbaum benjami...@gmail.com wrote: Why? What advantage would it offer? See Scott’s previous email: On Mon, Jun 29, 2015 at 8:42 PM, C. Scott Ananian ecmascr...@cscott.net wrote: Imagine trying to ensure that any characters over \u007f were escaped.

Re: RegExp.escape()

2015-06-30 Thread Benjamin Gruenbaum
I'm still not sure if it's worth it, after all it's just sugar for `RegExp.escape(str).replace(/[a-z]/gu, m = `\\${m}`)` On Tue, Jun 30, 2015 at 10:35 AM, Mathias Bynens mathi...@opera.com wrote: On Mon, Jun 29, 2015 at 9:04 PM, Benjamin Gruenbaum benjami...@gmail.com wrote: Why? What

Re: RegExp.escape()

2015-06-30 Thread C. Scott Ananian
On Tue, Jun 30, 2015 at 3:46 AM, Benjamin Gruenbaum benjami...@gmail.com wrote: I'm still not sure if it's worth it, after all it's just sugar for `RegExp.escape(str).replace(/[a-z]/gu, m = `\\${m}`)` I think you're making my point! And I hope your version of `RegExp.escape` doesn't use

Re: RegExp.escape()

2015-06-29 Thread Benjamin Gruenbaum
Why? What advantage would it offer? On Mon, Jun 29, 2015 at 9:49 PM, C. Scott Ananian ecmascr...@cscott.net wrote: And I'm suggesting that `RegExp.escape(str, /[image: ☺]/ug)` is a much better idea.​ --scott ___ es-discuss mailing list es-discuss

Re: RegExp.escape()

2015-06-29 Thread Allen Wirfs-Brock
On Jun 27, 2015, at 9:17 AM, Mark S. Miller wrote: Safety over readability please. If there is a single fully escaped form that is safe to use in all the expected contexts, let's choose that. The results of RegExp.escape are not very readable anyway, and rarely read. So compromising

Re: RegExp.escape()

2015-06-29 Thread C. Scott Ananian
And I'm suggesting that `RegExp.escape(str, /[image: ☺]/ug)` is a much better idea.​ --scott ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: RegExp.escape()

2015-06-29 Thread Benjamin Gruenbaum
This is currently discussed at https://github.com/benjamingr/RegExp.escape/issues/29#issuecomment-116789780 . Adding my comment from there to here too: Some languages (PHP for example) do this (optional parameter with additional parameters) so it's not unprecedented. The question we should ask

Re: RegExp.escape()

2015-06-29 Thread C. Scott Ananian
Please, not an iterable over characters. (Or at least, not only.) Use a RegExp. Imagine trying to ensure that any characters over \u007f were escaped. You don't want an iterable over ~64k characters. In addition, a RegExp would allow you to concisely specify hex digits, but only at the start

Re: RegExp.escape()

2015-06-29 Thread Benjamin Gruenbaum
I meant something like `RegExp.escape(str, ☺)` (also escapes `☺`). Since strings are iterable by code points via the new iteration protocol this sounds like the natural choice. I'm not sure such a second argument would be a good idea. On Mon, Jun 29, 2015 at 9:42 PM, C. Scott Ananian ecmascr

Re: RegExp.escape()

2015-06-27 Thread Mark S. Miller
Safety over readability please. If there is a single fully escaped form that is safe to use in all the expected contexts, let's choose that. The results of RegExp.escape are not very readable anyway, and rarely read. So compromising safety for some contexts in exchange for incremental readability

Re: RegExp.escape()

2015-06-27 Thread Benjamin Gruenbaum
I'd like to give https://github.com/benjamingr/RegExp.escape/issues/29 another week *please, if you have a strong opinion voice it* after which we'll settle on a hopefully *final* API for RegExp.escape in terms of the escaped parts. Some parts so you won't have to read the whole thread (debated

Re: RegExp.escape()

2015-06-20 Thread Benjamin Gruenbaum
As a cross-cutting concern I'd like the feedback of more people on https://github.com/benjamingr/RegExp.escape/issues/29 Basically we've got to make a design choice of readable output vs. potentially safer output. ___ es-discuss mailing list es-discuss

Re: RegExp.escape()

2015-06-20 Thread Bucaran
...@gmail.com wrote: As a cross-cutting concern I'd like the feedback of more people on https://github.com/benjamingr/RegExp.escape/issues/29 https://github.com/benjamingr/RegExp.escape/issues/29 Basically we've got to make a design choice of readable output vs. potentially safer output

Re: RegExp.escape()

2015-06-20 Thread Benjamin Gruenbaum
Why is this a comment on the RegExp.escape discussion? ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: RegExp.escape()

2015-06-13 Thread Allen Wirfs-Brock
On Jun 13, 2015, at 1:18 PM, C. Scott Ananian wrote: To throw some more paint on the bikeshed: The instanceof RegExp and RegExp(...) parts of the perfect implementation of `RegExp.tag` should also be fixed to play nicely with species. I think Allen and I would say that you should

Re: RegExp.escape()

2015-06-13 Thread Allen Wirfs-Brock
On Jun 13, 2015, at 4:16 PM, Allen Wirfs-Brock wrote: On Jun 13, 2015, at 1:18 PM, C. Scott Ananian wrote: To throw some more paint on the bikeshed: The instanceof RegExp and RegExp(...) parts of the perfect implementation of `RegExp.tag` should also be fixed to play nicely with

Re: RegExp.escape()

2015-06-13 Thread Mark S. Miller
Perfection? function re(first, ...args) { let flags = first; function tag(template, ...subs) { const parts = []; const numSubs = subs.length; for (let i = 0; i numSubs; i++) { parts.push(template.raw[i]); const subst = subs[i] instanceof RegExp ?

Re: RegExp.escape()

2015-06-13 Thread Mark S. Miller
The point of this last variant is that data gets escaped but RegExp objects do not -- allowing you to compose RegExps: re`${re1}|${re2}*|${data}` But this requires one more adjustment: function re(first, ...args) { let flags = first; function tag(template, ...subs) { const

Re: RegExp.escape()

2015-06-13 Thread C. Scott Ananian
On Sat, Jun 13, 2015 at 1:51 AM, Mark S. Miller erig...@google.com wrote: Nice! Inspired // Based on // https://github.com/benjamingr/RexExp.escape/blob/master/polyfill.js function re(template, ...subs) { const parts = []; const numSubs = subs.length; for (let i = 0; i

Re: RegExp.escape()

2015-06-13 Thread Mark S. Miller
Good idea bug infinite recursion bug. Fixed: function re(first, ...args) { let flags = first; function tag(template, ...subs) { const parts = []; const numSubs = subs.length; for (let i = 0; i numSubs; i++) { parts.push(template.raw[i]);

RE: RegExp.escape()

2015-06-13 Thread Domenic Denicola
All of these should be building on top of RegExp.escape :P From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Mark S. Miller Sent: Saturday, June 13, 2015 02:39 To: C. Scott Ananian Cc: Benjamin Gruenbaum; es-discuss Subject: Re: RegExp.escape() The point of this last variant

Re: RegExp.escape()

2015-06-13 Thread Mark Miller
] = Object.freeze('^$\\.*+?()[]{}|'.split(''));` or something? Then @exec could reference that, and similarly `RegExp.escape` and RegExpSubclass.escape` could reference it as well? On Sat, Jun 13, 2015 at 11:07 AM, Mark S. Miller erig...@google.com wrote: On Sat, Jun 13, 2015 at 9:17 AM

Re: RegExp.escape()

2015-06-13 Thread C. Scott Ananian
To throw some more paint on the bikeshed: The instanceof RegExp and RegExp(...) parts of the perfect implementation of `RegExp.tag` should also be fixed to play nicely with species. I think Allen and I would say that you should *not* use the species pattern for instantiating the new regexp

Re: RegExp.escape()

2015-06-13 Thread Benjamin Gruenbaum
On Sat, Jun 13, 2015 at 9:07 PM, Mark S. Miller erig...@google.com wrote: On Sat, Jun 13, 2015 at 9:17 AM, Domenic Denicola d...@domenic.me wrote: All of these should be building on top of RegExp.escape :P It's funny how, by considering it as leading to a proposal, I quickly saw deep

Re: RegExp.escape()

2015-06-13 Thread Mark S. Miller
On Sat, Jun 13, 2015 at 11:39 AM, Benjamin Gruenbaum benjami...@gmail.com wrote: On Sat, Jun 13, 2015 at 9:07 PM, Mark S. Miller erig...@google.com wrote: On Sat, Jun 13, 2015 at 9:17 AM, Domenic Denicola d...@domenic.me wrote: All of these should be building on top of RegExp.escape :P

Re: RegExp.escape()

2015-06-13 Thread Benjamin Gruenbaum
: On Sat, Jun 13, 2015 at 9:07 PM, Mark S. Miller erig...@google.com wrote: On Sat, Jun 13, 2015 at 9:17 AM, Domenic Denicola d...@domenic.me wrote: All of these should be building on top of RegExp.escape :P It's funny how, by considering it as leading to a proposal, I quickly saw deep flaws

Re: RegExp.escape()

2015-06-13 Thread Mark S. Miller
On Sat, Jun 13, 2015 at 9:17 AM, Domenic Denicola d...@domenic.me wrote: All of these should be building on top of RegExp.escape :P I am not yet agreeing or disagreeing with this. Were both to become std, clearly they should be consistent with each other. At the time I wrote this, it had

Re: RegExp.escape()

2015-06-13 Thread Jordan Harband
Would it help subclassing to have the list of syntax characters/code points be on a well-known-symbol property? Like `RegExp.prototype[@@syntaxCharacters] = Object.freeze('^$\\.*+?()[]{}|'.split(''));` or something? Then @exec could reference that, and similarly `RegExp.escape

Re: RegExp.escape

2015-06-12 Thread Benjamin Gruenaum
I made an initial repo https://github.com/benjamingr/RexExp.escape/blob/master/README.md I've added a reference to that gist - I'll start poking around and have scheduled to meet with some local people interested in helping next week. I'll keep you updated. On Fri, Jun 12, 2015 at 9:57 PM, Juriy

Re: RegExp.escape

2015-06-12 Thread C. Scott Ananian
}|def${ /a reg|exp/ })$` // apply flags? var pattern = RegExp.join('x')` abc | def \$`; ``` `RegExp.escape()` would be used internally to handle the interpolation of an string into the regexp. But these features are orthogonal. --scott On Fri, Jun 12, 2015 at 2:57 PM, Juriy Zaytsev kan

Re: RegExp.escape

2015-06-12 Thread Benjamin Gruenaum
You know what? Why not. I'm going to try to champion this. I talked to Domenic and he said he's willing to help me with this which is a big help (this would be my first time). I'll open a GitHub repo and see what I can come up with. ___ es-discuss

Re: RegExp.escape

2015-06-12 Thread Juriy Zaytsev
I made this gist back in the days — https://gist.github.com/kangax/9698100 — and I believe Rick was going to bring it up at one of the meetings. I don't have time to set up repo and work with TC39 member so if you can continue carrying that torch, that would be awesome! -- kangax On Fri, Jun

Re: RegExp.escape()

2015-06-12 Thread Mark S. Miller
Nice! Inspired // Based on // https://github.com/benjamingr/RexExp.escape/blob/master/polyfill.js function re(template, ...subs) { const parts = []; const numSubs = subs.length; for (let i = 0; i numSubs; i++) { parts.push(template.raw[i]);

Re: RegExp.escape()

2015-06-12 Thread Benjamin Gruenbaum
Ok, with a ton of help from Domenic I've put up http://benjamingr.github.io/RexExp.escape/ Less cool coloring but more links and motivating examples and so on at https://github.com/benjamingr/RexExp.escape As this is my first attempt at this sort of thing - any non-bikeshed feedback would be

Re: RegExp.escape

2015-06-12 Thread Benjamin Gruenaum
Reviving this, a year passed and I think we still want this. We have even more validation than we had a year ago (added by libraries like lodash) and this is still useful. What would be the required steps in order to push this forward to the ES2016 spec?

Re: RegExp.escape

2015-06-12 Thread Alexander Jones
At risk of bikeshed, I think I would prefer syntax for it, personally, e.g.: let myRegExp = /\d+\./{arbitrary.js(expression)}/SOMETHING$/; (ASI issues notwithstanding) vaguely matching the idea of template strings. I prefer this kind of thing to be structured at the parse-level rather than

Re: RegExp.escape

2015-06-12 Thread Jordan Harband
The primary advantage to making it be a function (also doing it as syntax would be great too!) is that it's polyfillable, which means that all browsers could instantly take advantage of known-safe regex escaping. On Fri, Jun 12, 2015 at 11:34 AM, Alexander Jones a...@weej.com wrote: At risk of

Re: RegExp.escape

2015-06-12 Thread Kris Kowal
I believe you need to champion the issue. Create a Github repository and start editing the fragment of the spec. I do not believe that the issue is contentious. The color of the shed is obvious. The only thing missing is a champion willing to do the writing. On Fri, Jun 12, 2015 at 10:52 AM,

Re: RegExp.escape

2014-03-21 Thread Mathias Bynens
: RegExp.escape = function(text) { return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$'); }; It escapes some characters that do not strictly need escaping to avoid bugs in ancient JavaScript engines. A standardized version could be even simpler, and would indeed be very welcome IMHO

Re: RegExp.escape

2014-03-21 Thread Kris Kowal
Continuing a 2 year old thread. http://esdiscuss.org/topic/regexp-escape ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: RegExp.escape

2014-03-21 Thread C. Scott Ananian
Thanks for the back-reference, Kris. So, everyone seemed to be in favor of this, it just never got formally added. @rwaldron, are you interested in championing this for ES7 as well? --scott On Fri, Mar 21, 2014 at 12:09 PM, Kris Kowal kris.ko...@cixar.com wrote: Continuing a 2 year old

Re: RegExp.escape

2014-03-21 Thread Rick Waldron
On Fri, Mar 21, 2014 at 4:29 PM, C. Scott Ananian ecmascr...@cscott.netwrote: Thanks for the back-reference, Kris. So, everyone seemed to be in favor of this, it just never got formally added. @rwaldron, are you interested in championing this for ES7 as well? Not until someone writes

Re: RegExp.escape

2014-03-21 Thread Juriy Zaytsev
How about this -- https://gist.github.com/kangax/9698100 Made it loosely based on B.2.1.1 (escape) -- kangax On Fri, Mar 21, 2014 at 5:56 PM, Rick Waldron waldron.r...@gmail.comwrote: On Fri, Mar 21, 2014 at 4:29 PM, C. Scott Ananian ecmascr...@cscott.netwrote: Thanks for the

Re: RegExp.escape()

2012-06-15 Thread T.J. Crowder
expressions include a built in method for this. For instance: * Perl: quotemeta(str) * PHP: preg_quote(str) * Python: re.escape(str) * Ruby: Regexp.escape(str) * Java: Pattern.quote(str) * C#, VB.NET: Regex.Escape(str) Indeed. +1 for RegExp.escape in ES. -- T.J

Re: RegExp.escape()

2012-06-15 Thread AJ ONeal
: Regexp.escape(str) * Java: Pattern.quote(str) * C#, VB.NET: Regex.Escape(str) Indeed. +1 for RegExp.escape in ES. -- T.J. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: RegExp.escape()

2012-06-15 Thread David Herman
On Mar 23, 2012, at 8:16 AM, Steven Levithan wrote: Although this is only a minor convenience since you can do something like text.replace(/[-[\]{}()*+?.,\\^$|]/g, \\$), the list of special characters is subject to change. That sounds like another good argument for standardizing. The only

Re: RegExp.escape()

2012-03-23 Thread Steven Levithan
On Wednesday, Jan 04, 2012 at 8:03 PM, Kris Kowal wrote: On Sun, Jun 13, 2010 at 7:50 AM, Jordan Osete jordan.os...@yahoo.fr wrote: Hello everybody. How about standardizing something like RegExp.escape() ? http://simonwillison.net/2006/Jan/20/escape/ It is trivial to implement, but it seems

Re: RegExp.escape()

2012-03-23 Thread Erik Corry
2012/3/23 Steven Levithan steves_l...@hotmail.com: On Wednesday, Jan 04, 2012 at 8:03 PM, Kris Kowal wrote: On Sun, Jun 13, 2010 at 7:50 AM, Jordan Osete jordan.os...@yahoo.fr wrote: Hello everybody. How about standardizing something like RegExp.escape() ? http://simonwillison.net/2006

Re: RegExp.escape()

2012-03-23 Thread Steven Levithan
Erik Corry wrote: Steven Levithan wrote: Kris Kowal wrote: Jordan Osete wrote: Hello everybody. How about standardizing something like RegExp.escape() ? http://simonwillison.net/2006/Jan/20/escape/ It is trivial to implement, but it seems to me that this functionality belongs

Re: RegExp.escape()

2012-03-23 Thread Steven Levithan
: Regexp.escape(str) * Java: Pattern.quote(str) * C#, VB.NET: Regex.Escape(str) -- Steven Levithan ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: RegExp.escape()

2012-01-04 Thread Kris Kowal
On Sun, Jun 13, 2010 at 7:50 AM, Jordan Osete jordan.os...@yahoo.fr wrote: Hello everybody. How about standardizing something like RegExp.escape() ? http://simonwillison.net/2006/Jan/20/escape/ It is trivial to implement, but it seems to me that this functionality belongs to the language

RegExp.escape()

2010-06-13 Thread Jordan Osete
Hello everybody. How about standardizing something like RegExp.escape() ? http://simonwillison.net/2006/Jan/20/escape/ It is trivial to implement, but it seems to me that this functionality belongs to the language - the implementation obviously knows better which characters must be escaped