Last active
March 9, 2020 16:56
-
-
Save bmcminn/584ce14d1670ca229fec050218c19af2 to your computer and use it in GitHub Desktop.
JS WTF?! Unsuspecting Regex range selector captures numbers and certain punctuation? Assuming it's due to a unicode/ascii coercion in the JS interpreter. Works in Node 5+ and in Browser console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"testing, waffles 1234567+=-_^@,./;:[]\/".replace(/[+-_]/g, '') | |
// > "testing waffles " |
UPDATE: it's intended behavior as a range selector... [+-_]
is a unicode coercion that matches all characters in that range.
Lesson learned: be explicit about your range capture values people, escape your hyphens \-
if you want to capture hyphens :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It has to do with the hyphen in the range
[+-_]
, so yes, ASCII coercion in the JS interpreter REGEX engine appears to be the case here.