slevithan / xregexp

Extended JavaScript regular expressions
http://xregexp.com/
MIT License
3.31k stars 278 forks source link

Regular expression with exclamation mark is not correctly matched #268

Closed amcghie closed 5 years ago

amcghie commented 5 years ago

Perhaps I'm not using XRegExp correctly. I'm getting a unexpected result when executing: XRegExp("^[\\pPd]+$").test("-!-")

XRegExp("^\\pPd+$").test("-!-") // -> false - correct
XRegExp("^[\\p{Dash_Punctuation}]+$").test("-!-") // -> false - correct
XRegExp("^[\\pPd]+$").test("-!-") // -> true - unexpected
// Replace \\pPd with the contents of "Dash_Punctuation" from "module.exports"
XRegExp("^[\\-\u058A\u05BE\u1400\u1806\u2010-\u2015\u2E17\u2E1A\u2E3A\u2E3B\u2E40\u301C\u3030\u30A0\uFE31\uFE32\uFE58\uFE63\uFF0D]+$").test("-!-"); // -> false - expected
slevithan commented 5 years ago

All of these results are correct, given that \pP matches !, and \pPd is two tokens -- \pP and d (literal character "d"). \p{Pd} is what you want.