Marker ord v2 reg exp
nedenstående kode markerer en tekst med anden baggrundsfarve. Det virker fint, men...Jeg ville egentlig gerne have den til ikke at markere <a href="www.testarea.dk"> men www.testarea.dk skal markeres?
jeg vil gerne have reg ex'en (?) til ikke at markere tekst der er i "situationstegn", hvis der ikke er spaces i (skal markere "der var en dag").
(så vil den ikke ødelægge linksne),
<html>
<head>
<title>markWord</title>
<script language="javascript">
function markWord(id, theword) {
if ( document.getElementById ) {
var elm = document.getElementById( id );
} else
if ( document.all ) {
var elm = document.all[ id ];
} else {
return; // sorry, NS4 er ikke med.
}
elm.innerHTML = elm.innerHTML.replace( new RegExp( theword, "gi" ), "<span style='background: #ffff33'>"+theword+"</span>" );
}
</script>
</head>
<body onload="markWord('a','test');">
<span name="a" id="a">
<table><tr><td>
<table><tr><td>
Lorem est a ipsum test dolor sit amet, consectetuer adipiscing elit, sed diam amex nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim des ad minim <a href="http://www.testarea.dk" target="_blank">www.testarea.dk</a>, quis nostrud exerci tation ullamcorper suscipit nfo lobortis
nisl ut aliquip ex ea commodo consequat.
</td>
</tr></table>
</td><td>
Lorem est a ipsum dolor sit amet, consectetuer adipiscing elit, sed diam amex nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam www.testarea.dk erat volutpat.
Ut wisi enim des ad minim veniam, quis nostrud exerci tation ullamcorper suscipit nfo lobortis
nisl ut aliquip ex ea commodo consequat.</td>
</tr></table>
</span>
</body>
</html>
