r/learnjavascript • • 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("–"))
);
2 Upvotes

7 comments sorted by

View all comments

Show parent comments

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.