regex - Unexpected working of Negated Shorthand Character Classes -
the regular expression
/[\d\s]/
should match characters not digit or not whitespace
but when test expression in regexpal
it starts matching character that's digit, whitespace
what doing wrong ?
\d
= characters except digits, \s
= characters except whitespaces
[\d\s]
= union (set theory) of above character groups = characters.
why? because \d
contains \s
, \s
contains \d
.
if want match characters not dights nor whitespaces can use [^\d\s]
.
Comments
Post a Comment