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)
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.)?
georg source share