Skip to content

Instantly share code, notes, and snippets.

@stash
Created July 10, 2013 16:00
Show Gist options
  • Select an option

  • Save stash/5967528 to your computer and use it in GitHub Desktop.

Select an option

Save stash/5967528 to your computer and use it in GitHub Desktop.
Does trailing dash in a regexp over-match?
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