65
rated 0 times
[
68]
[
3]
/ answers: 1 / hits: 16097
/ 8 Years ago, thu, may 26, 2016, 12:00:00
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
More From » regex