The Little Guy Posted January 15, 2013 Share Posted January 15, 2013 (edited) I have a string of text That could look like this: I am a paragraph * I am a list item * I am another list item * I am a third list item I am another paragraph What I would like to do, is convert the asterisk lines to an un-ordered list, The format would be: space asterisk space line of text What kind of regexp would be needed for something like that? Edited January 15, 2013 by The Little Guy Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 15, 2013 Author Share Posted January 15, 2013 (edited) Hmm... Looks like I got it: val = val.replace(/^ \* (.+?)(\n|$)/gm, "<li>$1</li>"); val = val.replace(/(<li>.+<\/li>)/igm, "<ul>$1</ul>"); Any suggestions? Edited January 15, 2013 by The Little Guy Quote Link to comment Share on other sites More sharing options...
nogray Posted January 16, 2013 Share Posted January 16, 2013 You can just add the ul tags in the first line of code val = '<ul>'+val.replace(/^ \* (.+?)(\n|$)/gm, "<li>$1</li>")+'</ul>'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.