21 cze 2009

Wydobycie tresci wyrażeniem regularnym RegExp

var tmp = null; var data =
'strona[ <a href="http://mapy.emiejsca.pl/egipt,egypt,miejsca.html">
http://mapy.emiejsca.pl/egipt,egypt,miejsca.html<a>
]';
var re = new RegExp(/strona\[(.*)\]/ig);
tmp=re.exec(data);
function deb_prop(tmp,ret) {
var obiekt_property = '';
for(j in tmp) obiekt_property += j + " "+ tmp[j] + "";
alert(obiekt_property);
}
alert(tmp[1]);
deb_prop(tmp);

W wyniku 2 alerty:
1:
---------------------------
Windows Internet Explorer
---------------------------
http://mapy.emiejsca.pl/egipt,egypt,miejsca.html
---------------------------
OK
---------------------------
2:
---------------------------
Windows Internet Explorer
---------------------------
input strona[ http://mapy.emiejsca.pl/egipt,egypt,miejsca.html ]
index 0
lastIndex 58
0 strona[ http://mapy.emiejsca.pl/egipt,egypt,miejsca.html ]
1 http://mapy.emiejsca.pl/egipt,egypt,miejsca.html
---------------------------
OK
---------------------------