Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
Last active January 28, 2023 18:08
Show Gist options
  • Save crazy4groovy/2085b9f952bf8bf6b4f93113c642f837 to your computer and use it in GitHub Desktop.
Save crazy4groovy/2085b9f952bf8bf6b4f93113c642f837 to your computer and use it in GitHub Desktop.
regex multi matching (JavaScript)
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;
// ...
}
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;
// ...
}
@crazy4groovy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment