Created
July 9, 2010 21:13
-
-
Save piouPiouM/470066 to your computer and use it in GitHub Desktop.
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
var str = 'Testons une <tag class="foobar" title="un > dans l\'attribut">regexp en Javascript</tag> <em>complexe</em>.', | |
reg = /<(\w+)((?:\s+\w+(?:\s*=\s*(?:"[\s\S]*?"|'[\s\S]*?'|[^'">\s]+))?)+\s*|\s*)>([\s\S]*?)<\/\1>/gi, | |
result = str.match(reg), | |
i = 0, | |
l = result.length, | |
r; | |
// Va afficher | |
// ["<tag class="foobar" tit...exp en Javascript</tag>", "<em>complexe</em>"] | |
console.info(result); | |
for (; l > i; i++) { | |
r = new RegExp(reg); | |
// Affiche le tableau de la capture de chacun des résultats | |
console.log(r.exec(result[i])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Réponse à un commentaire sur le billet Capturer les balises HTML et leur contenu avec une RegExp sous JavaScript.