I have a string of elements on multiple lines (but i can change this to being all on one line if necessary) and I want to split it on the <section> element. I thought this would be easy, just str.split(regex), or even str.split('<section') but it's not working. It never breaks the sections out.
I've tried using a regular expression SecRegex = /<section.?>[\s\S]?</section>/; var fndSection = result.split(SecRegex);
Tried var fndSection = result.split('<section');
I've looked all over the net and from what I've found one of the two methods above should have worked.
result = '
<chapter id="chap1">
<para0><title></title></para0>
</chapter>
<chapter id="chap2"> <title>THEORY</title>
<section id="Thoery">
<title>theory Section</title>
<para0 verstatus="ver">
<title>Theory Para 0 </title>
<text>blah blah</text>
</para0>
</section>
<section id="Next section">
<title>title</title>
<para0>
<title>Title</title>
<text>blah blah</text>
</para0>
</section>
<section id="More sections">
<title>title</title>
<para0>
<title>Title</title>
<text>blah blah</text>
</para0>
</section>
<section id="section">
<title>title</title>
<para0>
<title>Title</title>
<text>blah blah</text>
</para0>
</section>
<chapter id="chap1">
<para0><title></title></para0>
</chapter>
<chapter id="chap1">
<para0><title></title></para0>
</chapter>
<chapter> <title>Chapter Title</title>
<section id="Section ID">
<title>Section Title</title>
<para0>
<title>Para0 Title</title>
<para>blah blah</para>
</para0>
</section>
<section id="Next section">
<title>title</title>
<para0>
<line>Title</line>
<text>blah blah</text>
</para0>
</section>
<section id="More sections">
<title>title</title>
<para0>
<list>Title</list>
<text>blah blah</text>
</para0>
</section>
<section id="section">
<title>title</title>
<para0>
<title>Title</title>
<text>blah blah</text>
</para0>
</section>
<ipbchap>
<tags></tags>
</ipbchap>
</body>
<rear>
<tags></tags>
</rear>
</doc>'
Code
SecRegex = /<section.*?>[\s\S]*?<\/section>/;
var fndSection = result.split(SecRegex);
console.log("result string " + fndSection);
This is the result I'm getting from the code I have
result string <chapter id="chap2"> <title>THEORY</title> , , , , <chapter id="chap1"> <para0> <title></title></para0> </chapter>
result string <chapter id="chap1"> <para0> <title></title></para0> </chapter>
result string <chapter
As you can see
What I want is a string of <section>.*?</section> into an array
Thank you everyone for looking at this and helping me. I appreciate all your help.
Maxine