So I am trying to write a regular expression for JavaScript that will allow me to replace ** with tags as a sort of self rolled Markdown to HTML converter.
e.g.
**bold**
-> <strong>bold</strong>
but
\**not**
-> **not**
because *
was escaped.
I have the following regular expression which seems to work well:
/(?<!\\)(?:\\\\)*(\*\*)([^\\\*]+)(\*\*)/g
However, JS does not support lookbehinds! I rewrote it using lookaheads:
/(\*\*)([^\\\*]+)*(\*\*)(?!\\)(?:\\\\)*/g
but this would require me to reverse the string which is undesirable because I need to support multibyte characters (see here). I am not completely opposed to using the library mentioned in that answer, but I would prefer a solution that does not require me to add one if possible.
Is there a way to rewrite my regular expression without using look behinds?
EDIT:
After thinking about this a little more, I'm even starting to question whether regular expressions is even the best way to approach this problem, but I will leave the question up out of interest.