Git Product home page Git Product logo

Comments (8)

RubenVerborgh avatar RubenVerborgh commented on May 16, 2024

For ranges, numerical values make more sense. But for individual characters that have an ASCII representation, it is much more readable to have them there.

from regenerate.

mathiasbynens avatar mathiasbynens commented on May 16, 2024

What printable ASCII characters do not need any escaping in JavaScript regular expression literals?

Here are all printable ASCII characters:

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

AFAIK, the following characters have to be escaped (prefixed with \) in JavaScript regular expressions:

$
(
)
*
+
.
?
[
\
^
{
|

That leaves the following list:

 !"#%&',-/0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ]_`abcdefghijklmnopqrstuvwxyz}~

Regenerate might return a character class that is wrapped in [], and even if it doesn’t, the output may be used in such a context, so - and ] must be escaped too. That leaves the following list of printable ASCII characters that do not need escaping:

 !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz}~

Are there any others in the above list that absolutely need escaping? @jdalton and @kitcambridge, I seem to recall you were aware of issues when not escaping ] etc. in certain (old) engines. Do you remember the details?

(Note that in Regenerate, non-ASCII symbols are escaped anyway (by design – Regenerate’s output should always be ASCII-only).)

from regenerate.

jdalton avatar jdalton commented on May 16, 2024

Ya I had to escape a few more for better narwhal/ringo support. See lodash/lodash@06d3740 (edge lodash).

}
]

from regenerate.

mathiasbynens avatar mathiasbynens commented on May 16, 2024

Ok so the final list of printable ASCII characters to escape is:

$()*+-.?[\]^{|}

And the list of printable ASCII characters that do not need escaping are:

 !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~

Thanks!

from regenerate.

jdalton avatar jdalton commented on May 16, 2024

Escaping / is required for some ancient version of Firefox (totally may not be relevant).

from regenerate.

mathiasbynens avatar mathiasbynens commented on May 16, 2024

Ooh – any ideas which exact version(s), or where I can find more info?

from regenerate.

jdalton avatar jdalton commented on May 16, 2024

You're gonna laugh at me, but it's Firefox v1 (I have a note in platform.js source)

from regenerate.

mathiasbynens avatar mathiasbynens commented on May 16, 2024

jaw drops

from regenerate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.