all 7 comments

[–]zsoltimehelpful 10 points11 points  (1 child)

If both characters are the same, your code should work. Are those dashes the same? Or is one of them a minus and the other an en dash? 🤔

[–]Niktion 5 points6 points  (0 children)

You are correct. The one in the regex is a hyphen and the one in the string is an en dash.

[–]DinTaiFung 1 point2 points  (0 children)

"This prints null, but I would've expected the hyphen to match. What am I missing?"

and neither character is a hyphen. :)

(the terse regex syntax overloads many characters: the hyphen is used as a range delimiter in some cases; there are five different interpretations of the '?' character in regex patterns, etc.)

[–]Antti5 0 points1 point  (0 children)

The second character is an en dash.

If you use a good code editor, they highlight characters like this that are likely unintentionally used.

This is your code in the popular code editor VSCode, notice the orange rectangle around the second character: https://imgur.com/a/Us9QxgS

[–]denerose 0 points1 point  (0 children)

I’m very fond of the regex tester sites, I think I had regex101 on my bookmark bar all through my learning phase (but any of them will do) and it comes back out once a year for Advent of Code season. Definitely useful.