0

I have to match every element that has an attribute 'class'='row' in order to use it as separator in javascript .split() method. How can I archive this with regular expressions? In the following string <div class="row" tabindex="0"> should be matched.

<div class="row" tabindex="0"><div class="cell">rect</div><div class="cell">A</div><div class="cell">0</div><div class="cell">0</div><div class="cell">10</div><div class="cell">10</div></div><div class="row" tabindex="0"><div class="cell">rect</div></div>
Oleksa
  • 635
  • 5
  • 15

1 Answers1

0

Just use jQuery and save yourself the headache.

let html = $(`  <div class="row" tabindex="0">
                    <div class="cell">rect</div>
                    <div class="cell">A</div>
                    <div class="cell">0</div>
                    <div class="cell">0</div>
                    <div class="cell">10</div>
                    <div class="cell">10</div>
                </div>
                <div class="row" tabindex="0">
                    <div class="cell">rect</div>
                </div>`);

let rows = html.filter('.row');

Then if you need the raw HTML string of a specific row:

let row1HTML = rows[0].innerHTML;
Jimmy Leahy
  • 566
  • 3
  • 14