Last active
October 2, 2017 10:29
-
-
Save devhero/51553d0677592607ffc5967053fd6172 to your computer and use it in GitHub Desktop.
regex tips
This file contains 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
// search 2 words multiline | |
(?=.*\bWORD1\b).*\n*(?=.*\bWORD2\b).* | |
// exclude word | |
\b((?!word)\w)+\b | |
// iterate over matches and do something with group's result | |
var myString = "something format_abc"; | |
var myRegexp = /(?:^|\s)format_(.*?)(?:\s|$)/g; | |
match = myRegexp.exec(myString); | |
while (match != null) { | |
// matched text: match[0] | |
// match start: match.index | |
// capturing group n: match[n] | |
console.log(match[0]) | |
match = myRegexp.exec(myString); | |
} | |
// iterate over matches and collect group's result | |
var matches = [] | |
while (match = myRegex.exec(myStr)) matches.push(match[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment