Skip to content

Instantly share code, notes, and snippets.

@mileszs
Created August 22, 2018 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mileszs/45d14aa525830f0f3f8ce5c4af393026 to your computer and use it in GitHub Desktop.
Save mileszs/45d14aa525830f0f3f8ce5c4af393026 to your computer and use it in GitHub Desktop.
var strToCheck = "here's some stuff and also squirrels 23 and other things";
var strToMatch = "squirrels";
// the double backslash prevents the backslash from being escaped by the RegExp constructor
// ... whee!
var regex = new RegExp(strToMatch + "\\s[0-9]{1,2}", "g");
var match = regex.exec(strToCheck);
// the result is that match now contains
// ["squirrels 23", index: 11, input: "some stuff squirrels 23 and things", groups: undefined]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment