Created
November 7, 2024 10:21
-
-
Save X-Raym/e46941c903c57a960d04201320ade7cd to your computer and use it in GitHub Desktop.
Javascript match all substring instances via regex and return array
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 htmlString = "Normal normal <u>souligné</u> normal normal <u>souligné</u>"; | |
const regex = /<u>(.+?)<\/u>/g; | |
let matches; | |
const results = []; | |
while ((matches = regex.exec(htmlString)) !== null) { | |
results.push({ | |
match: matches[1], | |
index: matches.index | |
}); | |
} | |
console.log(results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment