1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
<html>
<head>
<script type='text/javascript'>
/**************************************
* Script prototype match_all *
* © Spacefrog 2010 *
* emulation du preg_match_all de php *
**************************************/
RegExp.prototype.match_all=function(mystring){
var res=[]
var match;
if (arguments.length>1){
var i=0;
while(arguments[++i]!= undefined){
res['$'+arguments[i]]=new Array()
}
while (match = this.exec(mystring)) {
var i=0;
while(arguments[++i]!=undefined){
match[+arguments[i]] && res['$'+arguments[i]].push(match[+arguments[i]]);
}
}
}
else{
while (match = this.exec(mystring)) {
res.push(match[0]);
}
}
return res;
}
var chaine = content.document.body;
//var chaine = new Array();
//var chaine = document.getElementsByTagName('body');
//var chaine = document.body;
//var chaine = document.html;
reg=/>(.*?)<\/a>/gi;
results=reg.match_all(chaine,1,2)
alert(results.$1 +'\n' + results.$2)
</script>
<title>Tous nos liens</title></head>
<body>
<a href="url1.htm"> bla1 </a><a href="url2.htm"> blabla22 </a><a href="url3.htm"> blabla3 </a><br>
<a href="url4.htm"> dans lapage </a><a href="url5.htm"> ht55 </a><a href="url3.htm"> num66 </a>
</body>
</html> |
Partager