Last active
January 28, 2023 18:08
-
-
Save crazy4groovy/2085b9f952bf8bf6b4f93113c642f837 to your computer and use it in GitHub Desktop.
regex multi matching (JavaScript)
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
const html ='<div><a title="123" href="http://xyz.com">link</a></div>'; | |
const regexGroups = /title="([^"]+)" href="([^"]+)"/gm; | |
const matches = html.matchAll(regexGroups); | |
for (const match of matches) { | |
let [, title, url] = 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
const html ='<div><a title="123" href="http://xyz.com">link</a></div>'; | |
const regexGroups = /title="([^"]+)" href="([^"]+)"/gm; | |
let match; | |
while ((match = regexGroups.exec(html)) !== null) { | |
let [, title, url] = match; | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll