Forum Moderators: open
test = "[img]http://www.com/image.jpg[/img]";
test.replace("\[img\](.*?)\[/img\]", "<img src='#1' />");
alert(test);
This should return the following:
<img src='http://www.com/image.jpg'>
However it returns:
So obviously its not matching.
test.match("\[img\](.*?)\[/img\]); doesnt work either
1) the regexp itself needed to be changed
2) even if yours had been correct, it would not have changed anything since you did not assign the replaced string to a variable ;)
<script type="text/javascript">
test = "
";
test = test.replace(/\[img\](.*?)\[\/img\]/g, "<img src=\"$1\" />");
alert(test);
</script>