I am making a simple JavaScript based WYSIWYG editor using regular expressions to do the conversion to html.
This is the javascript conversion method I am using
message = message.replace(/\*\*(.*)\*\*/g, "<b>$1</b>");
It converts text surrounded with two ** to bold.
The issue is that it does not do that for every instance.
Instead it does it from the first instance of ** to the last.
So **bold text** **bold text**
Gives me
bold text* *bold text
<b>bold text* *bold text</b>
Instead of
<b>bold text</b> <b>bold text</b>
How can I set it up to convert each instance instead of grouping them together?
You need to change the quantifier to
.*?to make it not greedy: