I need a regular expression for extracting the paragraph inside div of class carousel-caption in html string coming from json api in react native app.
var m,
array= [],
str = '
<p>some other text .....  </p>
<div class="carousel-caption d-none d-md-block">\n\n                <p>some text .....  </p></div>
<div class="carousel-caption d-none d-md-block">\n\n                \n            </div>
<div class="carousel-caption d-none d-md-block">\n\n                <p>some text .....  </p></div>
<div class="carousel-caption d-none d-md-block">\n\n                <p>some text .....  </p></div>
<p>some other text .....  </p>';
    rex = /<div [^<>]+carousel-caption[^<>]+>\s*<p>(.+?)<\/p>/g;
    do {
        m = rex.exec(str);
        if (m) {
            console.log(m[1]);
        }
    } while (m);
I have multiple div with classes of name carousel-caption contain single paragraph in each, and i have some paragraphs that are not in class carousel-caption, with rex i can get paragraphs inside carousel-caption div class, however I want the array to have empty field in case the div contains no paragraph while maintaining the order, because i need the caption under its image, and some image do not have caption.
 
     
    