I have the following JavaScript (the spaces in the <P>
s are non-breaking):
var html = '...<li>sub 2</li></ol></li></ol>\n\
<p> i. subsub 1</p>\n\
<p> ii. subsub 2</p>\n\
<ol start="2"> \n\
<ol start="3"> \n\
<li>sub 3</li></ol>...';
$(function () {
var nestedListFixer = /(?:<\/li><\/ol>\s*)+(?:<p>(?:&(?:nbsp|\#0*160|x0*A0);)+(?:\s[ivxlcdm]+\.)(?:&(?:nbsp|\#0*160|x0*A0);)+\s(.*?)<\/p>\s*)+(?:<ol(?:\sstyle=\"[^\"]+\")?\sstart=\"[^\"]+\">\s*)+/i;
html = html.replace(nestedListFixer, function($0, $1){
var lis = ""
$.each($1, function () {
lis += "<li>" + this + "</li>\n";
});
alert("<ol>\n" + lis + "</ol></li>");
return "<ol>\n" + lis + "</ol></li>";
});
});
The alert()
's output:
<ol>
<li>s</li>
<li>u</li>
<li>b</li>
<li>s</li>
<li>u</li>
<li>b</li>
<li> </li>
<li>2</li>
</ol></li>
Here's what I hoped it would be:
<ol>
<li>subsub 1</li>
<li>subsub 2</li>
</ol></li>
How do I correctly loop through each match in the $1
?
Update: simplified pattern and matching example:
var text = '1ab2cb3cd4ab5cb6cd7';
$(function () {
var textFixer = /(?:a)(?:b(.*?)c)+(?:d)/i;
text = text.replace(textFixer, function($0, $1){
var numbers = "";
$.each($1, function () {
numbers += this;
});
alert(numbers);
return numbers;
});
alert(text);
});
// actual text:
// 13467
// desired text:
// 1234567