I have a string as follows:
<abc name = "foo">
  <child>bar</child>
</abc>
<xyz>1</xyz>
<abc name = "foo2">
  <child>bar2</child>
</abc>
<xyz>5</xyz>
I have created a regex as follows:
var regexapi = /<abc\s*name\s*=\s*"(.*?)"[\s\S]*?<\/abc>\n*<xyz>/gim;
while ( (resApi = regexapi.exec(data))) {
    array1.push(resApi[0]);
}
console.log(array1[0]);
Now if I don't have the tag <xyz>1</xyz> printing array1[0] should show undefined but it is printing as follows:
    <abc name = "foo">
  <child>bar</child>
</abc>
<abc name = "foo2">
  <child>bar2</child>
</abc>
<xyz>
I think there is some problem in  \n* since I'm giving multiline flag. Not sure aout this though.
Note that this is without <xyz>1</xyz> tag. I want it to print undefined.
Thanks.
 
     
    