Character display ranges with character screens

From my point of view, this

/[\dX]/ 

not allowed by standard:

The CharacterRange abstract operation takes two CharSet parameters A and B and does the following: 1. If A does not contain exactly one character or B does not contain exactly one character, then throw a SyntaxError exception ... ( http://es5.imtqy.com/# x15.10.2.15 )

However, some (most?) Browsers interpret it as an ordinal character, if it is preceded / followed by an escape, so the above corresponds to numbers, dashes, and X:

 var re = /[\dX]/g; for(var i = 0, r = ""; i < 0x10000; i++) { var s = String.fromCharCode(i); if(!s.replace(re, '')) r += s; } console.log(r) // -0123456789X 

Questions:

  • Is this behavior observed in all engines? (I tested the latest Webkit and Firefox)
  • Are there any explanations why they decided to violate the standard (in documents, sources, mailing lists, etc.)?
+4
source share
1 answer

I think note 3 under 10.15.2.16 NonemptyClassRangesNoDash in the standard answers it:

A - a symbol can be interpreted literally or it can indicate a range. this is handled literally if it is the first or last character of ClassRanges, the start or end limit of the range specification, or immediately follows the range specification.

In this case, I think that immediately follows a range specification applies.

Some other examples: [afh] [\s--9] [\w\d-\s]

+4
source

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


All Articles