Sizzle regex JScript for CLASS?

I looked at the Prototype.js code and I saw there (in the Sizzle part):

enter image description here

My question is about this line:

CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,

\. for a point, next (unoccupied group: words, range and - ) OR ( \. ). (he actually says \\. , but the first one is just for shielding, so he \. ).

A?

What \. ?

I checked /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/.test('.aa\.') And it returns true .

But what is .aa\. ? obviously .aa class, but if \ is a valid char, why is it not in the [..] section?

What am I missing?

+6
source share
1 answer

\\. matches a literal backslash followed by any character (dot not escaped).

From http://Sizzlejs.com/ :

Hidden selector support #id \: value

It is used to map classes like a\~b , and it actually repeats in most selectors in your screenshots. This is usually the case when you have periods or brackets in names or classes.

As for your test:

  • In JavaScript, invalid escape sequences are ignored . "\." === "." , and your test will be the same as .test('.aa.') .
  • .test allows a partial match - /\w+/.test("a!") === true - this does not mean that the last point was actually matched.
+3
source

Source: https://habr.com/ru/post/959334/


All Articles