0

I would like to use regex to get some data from my existing html , my html is as below

<h2 style="text-align: center;"><strong>Title/strong></h2>
<h1 style="text-align: center;">Latest Update : 11-12-209</h1>
<h1 style="text-align: center;"><strong>Comics</strong></h1>

<hr />

<a href="" alt="" width="300" height="169" class="" /></a>

<strong>Ttile: Book1</strong>
<strong>ISBN : 1234567ND​​</strong>


<hr />
<a href="" src="" alt="" width="200" height="300" /></a> <a href=""><img class="" src="" alt="" width="300" height="225" /></a>

   <strong>Ttile: Book2</strong>
<strong>ISBN : 12345678ND​​</strong>

<hr />

My Expected data would be from the first < hr > to the last < hr > ,

I try regex ^ to last < HR >.

What is the correct regex that allow me to get my expected result

abc cba
  • 2,563
  • 11
  • 29
  • 50
  • The pattern `
    (.*)
    ` _might_ work, but you should really consider using an HTML parser (e.g. JavaScript).
    – Tim Biegeleisen Nov 16 '17 at 13:29
  • Possible duplicate of [RegEx match open tags except XHTML self-contained tags](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – treyhakanson Nov 16 '17 at 13:45

1 Answers1

0

Here is a working example:

var html = '<h2 style="text-align: center;"><strong>Title/strong></h2>\
<h1 style="text-align: center;">Latest Update : 11-12-209</h1>\
<h1 style="text-align: center;"><strong>Comics</strong></h1>\
<hr />\
<a href="" alt="" width="300" height="169" class="" /></a>\
<strong>Ttile: Book1</strong>\
<strong>ISBN : 1234567ND​​</strong>\
<hr />\
<a href="" src="" alt="" width="200" height="300" /></a> <a href=""><img class="" src="" alt="" width="300" height="225" /></a>\
<strong>Ttile: Book2</strong>\
<strong>ISBN : 12345678ND​​</strong>\
<hr />';

console.log( html.match(/<hr \/>(.*)<hr \/>/i)[1] );
YouneL
  • 8,152
  • 2
  • 28
  • 50