I want to replace *hello*
to hello how will i be able to do that? and the same but with other prefixes
let content = '*Hello*, my **friend** how are you?'
function formatString(content) {
let step1 = content.split(" ").join(" ").replaceAll("nn", "</br></br>");
//replace
}
formatString(content)//should return '<i>Hello</i>, my <b>friend</b> how are you?'
I tried using regex but I was only able to replace *string*
to string only instead of string
2
Answers
the replaceAll method with the regex /*(.?)*/g to replace all occurrences of string with string, and /**(.?)**/g to replace all occurrences of string with string. The g flag makes sure that all occurrences are replaced, not just the first one.
You could use the ShowdownJS library to handle Markdown to HTML conversion.