Hi,
My objective is to replace all pattern words that match a particular regex with that word surrounded in some html tags like so.
Example html:
<p>This is some text where the word text will get surrounded by something else.</p>
After regex:
<p>This is some <span class='mydiv'>text</span> where the word <span class='mydiv'> will get surrounded by something else.</p>
Note that as this is a simple example used to illustrate my problem, I cannot simply do this...
$(document).html($(document).html().replace(/text/g,"<span class='mydiv'>text</span>"));
The original problem comprises a large regular expression that will accept a large range of inputs and the text is allowed to contain spaces. So text, t E x T and other derivatives will be allowed and I wouldn't want to change the original styling/format to a static replacement word "text" I'd like the original wording/casing etc. there within the replacement.
Anyone know how to do this?