I’m trying to do a parse of html content using jQuery/Javascript. I want to look for words between square brackets and change the whole word for a link.
Example:
<div>
This is text inside a div. It has a reference to an [[Article]]
</div>
I’m trying to use Regular Expressions to change what’s inside the double brackets into something like this:
<div>
This is text inside a div. It has a reference to an <a href='/dictionary#Article'>Article</a>
</div>
I can find all instances of words between square brackets with this regex:
$('article').html().match(/[^[\]]+(?=])/g)
But don’t know how to replace the text.
DEMO: http://jsfiddle.net/y4N6e/