I'm looking to match bolded markdown. Here are some examples:
qwer *asdf* zxcv
matches *asdf*
qwer*asdf*zxcv
matches *asdf*
qwer \*asdf* zxcv
does not match
*qwer* asdf zxcv
matches *qwer*
A negative look behind like this (?<!\\)\*(.*)\*
works.
Except there is no browser support in Firefox, so I cannot use it.
Similarly, I can get very close with (^|[^\\])\*(.*)\*
The issue is that there are two capture groups, and I need the index of the second capture group, and Javascript only returns the index of the first capture group. I can bandaid it in this case by just adding 1, but in other cases this hack will not work.
My reasoning for doing this is that I'm trying to replace a small subset of Markdown with React components. As an example, I'm trying to convert this string:
qwer *asdf* zxcv *123*
Into this array:
[ "qwer ", <strong>asdf</strong>, " zxcv ", <strong>123</strong> ]
Where the second and fourth elements are created via JSX and included as array elements.