Regex Not Working "within" Javascript String
I'm trying to replace all mentions of [b] in a text string and replace it with . The problem with what I'm using below this that it's replace every [b] on the page, and I
Solution 1:
I'm not exactly sure what the problem is because the question is a bit unclear. Are you trying to replace the content within the textarea with the new html tags?
The following code is currently working for me in production:
text = $("#contract_body").val(); // strore the current contents
text = text.replace(/\[b\](.*?)\[\/b\]/gim, "<strong>$1</strong>"); // replace bbcode with html tags
$("#contract_body").val(text); // update the textarea with the new string contents
I hope that helps.
Post a Comment for "Regex Not Working "within" Javascript String"