jquery - Replace all content between characters with JavaScript -
I am trying to create a simple markdown converter for getting better at JS and Regex.
I now need to find everything between two asterisks, and they & lt; I & gt; Wrap the tag:
var html = '* abc wire *'; Var html = html.replace (/ \ * / g, ' gt;'); Console.log (html); RESULT:
& lt; I & gt; ABC is a string & lt; I & gt;
I also answer a related question, but I am unsure about how to adjust my code accordingly, or what it really is:
(? S) & lt; H1>. & Lt; / H1>
Any help would be great.
Get content wrapped in HTML tags:
Var html = html.replace (/ \ * ([^ *] +) \ * / g, ' $ 1 & lt; / i & gt;'); Explanation of ([^ *] +) : (# Start of Capture group [^ # Start of denial] So
then [^ *] + means "at least one letter that matches the * is not. It has the effect that all the characters from next to * are matched.
Comments
Post a Comment