Created
July 10, 2013 16:00
-
-
Save stash/5967528 to your computer and use it in GitHub Desktop.
Does trailing dash in a regexp over-match?
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
| var unescaped = new RegExp('^[0-9_-]+$'); | |
| var escaped = new RegExp('^[0-9_\\-]+$'); | |
| var literal = /^[0-9_-]+$/; | |
| // _ is 0x5f, a is 0x61. If "_-" over-matches then "a_" will match the above. | |
| var test = "a_"; | |
| console.log("unescaped:", test.match(unescaped)); | |
| console.log("escaped:", test.match(escaped)); | |
| console.log("literal:", test.match(literal)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment