The regular expression below matches all sequences closely associated with single asterisk characters, resulting in italicized text in Markdown. I want to format text, including asterisks, used for underlining. In addition to this, I allow free-standing asterisks within the sequence. An example *This is italic text\n with * in between*.
/\*[^\*\s]([^\*]|(\*\s))*[^\*\s]\*/g
Markdown also underlines bold text with very similar, double asterisk characters. To match them, I use this regex:
/\*\*[^\*\s]([^\*]|(\*\s))*[^\*\s]\*\*/g
Both work on their own, but when used together, the inside of a bold text is also defined as italic text. Therefore, with the exception of external asterisks, formatted text is shown in bold and italics. To fix this, I would have to express italic sequences that cannot be wrapped in a second pair of asterisks.
The problem is that [^\*]any other character is required, so a character in general is required. How can I express that the first regular expression above does not match if they are extra asterisks wrapped around, still matching at the very beginning or end of the search string?
As a note, I use JavaScript, so there is no appearance.