I have a string with markdown in it. I am trying to strip all markdown using regex but am having trouble with matching links. Here's how far I got:
function stripMarkdown(text) {
var str = String(text).replace(/(__|\*|\#)/gm, '');
return str;
}
var testStr = '# This is the title. ## This is the subtitle. **some text** __some more text__. [link here](http://google.com)'
stripMarkdown(testStr);
So I believe the above will strip all unwanted markdown except the link. How do I handle that? Also, if there's a better way to do this, please let me know.
Desired outcome:
This is the title. This is the subtitle. some text some more text. link here
I came up with this regex:
(?:__|[*#])|\[(.*?)\]\(.*?\)
var str = '# This is the title. ## This is the subtitle. **some text** __some more text__. [link here](http://google.com)'
document.write(String(str).replace(/(?:__|[*#])|\[(.*?)\]\(.*?\)/gm, '$1'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With