« Return to Thread: Regular expression /\d/ matches "digits" other than

Regular expression /\d/ matches "digits" other than

by Igor Tandetnik :: Rate this Message:

Reply to Author | View in Thread

/\d/.test("\uFF11")

returns true. U+FF11 is FULLWIDTH DIGIT ONE, and happens to have Unicode
class Nd (decimal number). However, Ecma-262 (the standard for
EcmaScript aka JavaScript) explicitly states:

15.10.2.12 CharacterClassEscape
The production CharacterClassEscape :: d evaluates by returning the
ten-element set of characters containing the characters 0 through 9
inclusive.

So accepting "digits" other than [0-9] appears to be a bug. Am I missing
something obvious?


I wouldn't mind this behavior, if things like parseInt would also
understand the same set of digits. I submit it should be the case that,
modulo overflow, for every (short enough) string s, if /^\d+$/.test(s)
returns true then parseInt(s, 10) should return a number other than NaN.

Yes, I realize that I can replace \d with [0-9] and \D with [^0-9]. This
makes even moderately complicated regular expressions considerably
harder to read though.

Igor Tandetnik


_______________________________________________
dev-i18n mailing list
dev-i18n@...
https://lists.mozilla.org/listinfo/dev-i18n

 « Return to Thread: Regular expression /\d/ matches "digits" other than