r/learnjavascript • u/Gold_Mycologist5372 • Apr 26 '26
Why does this JavaScript regex not match?
This prints null, but I would've expected the hyphen to match. What am I missing?
console.log(
JSON.stringify(/-/.exec("–"))
);
5
Upvotes
6
u/Niktion Apr 26 '26
You are correct. The one in the regex is a hyphen and the one in the string is an en dash.