Forum Moderators: open
body = body.replace(/\[url\=([^]])\](.*?)\[\/url\]/g, "<a href='$1'>$2</a>");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<script type="text/javascript">
function replaceTest(obj) {
if (document.getElementById) {
var txt=document.getElementById(obj).innerHTML;
alert(txt);
txt = txt.replace(/\[url=([^\]]*)\]([^\[]*)\[\/url\]/ig, '<a href="$1">$2</a>');
alert(txt);
}
}
</script>
</head>
<body>
<p><a href="#" onClick="return replaceTest('my_p');">test</a></p>
<p id="my_p">[url=http://example.com]example.com[/url]</p>
</body>
</html>
I think it might have been you forgot a couple things. A dissection:
\[url= starts with
([^\]]*) zero or more of anything not a ], store in $1
\] followed by this
([^\[]*) zero or more of anything not a [, store in $2
\[\/url\] followed by the closing BB code.
Note I also added the i flag for case-insensitive.