-3

So, i got some html tables that i need to extract values, did a regular expression to get the values i wanted.

the html tables can be in these 2 formats:

<td height="20" style="width:59px;height:20px;">1</td>
            <td style="width:212px;">Mendes, Paulo [AA]</td>
            <td style="width:99px;">39</td>
            <td>8</td>
            <td style="width:85px;">$10,000</td>
        </tr><tr height="20"><td height="20" style="width:59px;height:20px;">2</td>
            <td style="width:212px;">Campos, Miguel [AC]</td>
            <td style="width:99px;">37</td>
            <td>6</td>
            <td style="width:85px;">$5,000</td>

And the other one

<td>1</td>
            <td>Mendes, Paulo [AA]</td>
            <td>39</td>
            <td>8</td>
            <td>$10,000</td>
        </tr><tr height="20"><td>2</td>
            <td>Campos, Miguel [AC]</td>
            <td>37</td>
            <td>6</td>
            <td>$5,000</td>

To the example without style i can get the values i want with this regex:

<td>(\d+)<\/td>\n+\t*<td>([\w+, ]+) \[(\w{2})\]<\/td>

its to be used in php, and i been using https://regex101.com/ to test the regex first.

now to get the values of the table with styles i'm getting no luck.

tried the "perfect match" with:

 <td height\=\"20\" style\=\"width\:59px\;height\:20px\;\">(\d+)<\/td>\n+\t*<td style\=\"width\:212px\;\">([\w+, ]+) \[(\w{2})\]<\/td>

but it doesn't catch want i want. even tried to do a negation search but it still doesn't work. What i'm doing wrong?

1 Answers1

0

Why don't you use QuerySelectorAll (''); it is a lot easier. You can used it to retrieve the inner text of td elements and store them in an array using a loop. Once you have the td you can use jQuery Ajax to send it to a .php file to process however you want.

For example:

var tdArr = [];

var tdContent = document.querySelectorAll('table tr td');

for ( let i = 0; i  < tdContent.length; i++){
    tdArr.push(tdContent[i].textContent);
}
smuhero
  • 19
  • 10