I've been experimenting with regex. I came up with a regex pattern that converts *
into <em>
, similar to Markdown:
el = el.replace(/\*\b/g, '<em>')
el = el.replace(/\b\*|(\.|\,|\?|\!|\*|---|\.\.\.\s)\*/g, '$1</em>')
It works well in most cases. However, things get messy when you apply this regex to the following text:
Chicken teriy*ai*ki, r*ai*men noodles, spaghetti a la moneg*ai*sque.
It produces this result:
Chicken teriy<em>ai<em>ki, r<em>ai<em>men noodles, spaghetti a la moneg<em>ai<em>sque. And wait for me, often falling asleep.</em></em></em></em></em></em>
Is there a way to modify this regex so it gives an output more like this:
Chicken teriy<em>ai</em>ki, r<em>ai</em>men noodles, spaghetti a la moneg<em>ai</em>sque. And wait for me, often falling asleep.