How can I replace some repeated characters using regex
?
This is what I have so far:
let message = "*test* _test_ ~test~"
let replacedMessage = message
.replace(/~(~*[^~\n]+~*)~/g, '<del>$1</del>')
.replace(/_(_*[^_\n]+_*)_/g, '<em>$1</em>')
.replace(/\*(\**[^*\n]+\**)\*/g, '<strong>$1</strong>')
.replace(/\n/g, '<br>')
return replacedMessage
These are the desired results:
*test* => <strong> //Bold
_test_ => <em> //Italic
~test~ => <del> //Strikethrough
```test``` => <pre> //Monospaced
How can I do the ``` replacement to <pre>
? I was unable to make this replacement with the regex.