Created
August 22, 2018 20:15
-
-
Save mileszs/45d14aa525830f0f3f8ce5c4af393026 to your computer and use it in GitHub Desktop.
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 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