The Little Guy Posted January 15, 2013 Share Posted January 15, 2013 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? Link to comment https://forums.phpfreaks.com/topic/273201-convert-asterisk-list-to-html-list/ Share on other sites More sharing options...
The Little Guy Posted January 15, 2013 Author Share Posted January 15, 2013 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? Link to comment https://forums.phpfreaks.com/topic/273201-convert-asterisk-list-to-html-list/#findComment-1405915 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>'; Link to comment https://forums.phpfreaks.com/topic/273201-convert-asterisk-list-to-html-list/#findComment-1406175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.