Skip to content

Instantly share code, notes, and snippets.

@piouPiouM
Created July 9, 2010 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piouPiouM/470066 to your computer and use it in GitHub Desktop.
Save piouPiouM/470066 to your computer and use it in GitHub Desktop.
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]));
}
@piouPiouM
Copy link
Author

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