How to make text formatting as in WhatsApp?

How to do such a thing, like in WhatsApp when writing in the input field *text* text in asterisks become bold, if I'm writing ~text~ that is crossed out.

Maybe someone used to do this? I would like the finished code, and that have already tried, nothing happens.

That is, I need to check whether at the end and in front of the characters. How?
April 7th 20 at 15:15
2 answers
April 7th 20 at 15:17
("my *test* text ~not~ ~b*a~d*")
.replace(/\*([^\*\~]+)\*/g, '<b>$1</b>')
.replace(/\~([^\*\~]+)\~/g, '<s>$1</s>')
// "my <b>test</b> text <s>not</s> ~b*a~d*"

The regular expression is looking for:
- star
- followed by anything but an asterisk and not other special characters and stores found (for this bracket),
- then another asterisk.

And replace found at:
+ start tag bold,
+ the fact that coincided in parentheses
+ closing tag.

Then the same thing for the symbol ~ and the strikethrough tag.
April 7th 20 at 15:19
See what is MD(Markdown). Well, for your tasks you need a parser for markdown.
Wow, I hear it only the first time, and something easy please? - Rodger77 commented on April 7th 20 at 15:22
@joyce.Johns3, here for you
https://github.com/markedjs/marked - Bennie_Jacobs commented on April 7th 20 at 15:25

Find more questions by tags JavaScript