Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Regex match just first result or second from HTML table

I'm using regex in-app script javascript. I try to get just the first value or the second value from each table but not work.

   <table>
      <td class="bar">
        <td class="center">hello1</td>
        <td class="center">hello2</td>
        <td class="center">hello3</td>
     </td>
   </table>

   <table>
     <td class="bar">
       <td class="center">hello1</td>
       <td class="center">hello2</td>
       <td class="center">hello3</td>
     </td>
   </table>

my code regex: /(?<=<td class=\"center\">).*?(?=<\/td>)/gi

this code selects all values Hello. I want just select Hello1 from the first table td and second table td. I remove global but give me just the first td from the first table.

the hello value is dynamic not fixed.

enter image description here

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You could do a regular expression something like this which retrieves the text you expect...

regular expression run results

Essentially matching the tags by excluding <> characters within the tag.

However I think an easier and less error prone way to do this in JavaScript and DOM is to use querySelectorAll instead, for example...

let c = document.querySelectorAll('td:nth-of-type(2)');

console.log(Array.from(c).map(i => i.innerText));
   <table>
      <td class="bar">
        <td class="center">hello1</td>
        <td class="center">hello2</td>
        <td class="center">hello3</td>
     </td>
   </table>

   <table>
     <td class="bar">
       <td class="center">hello1</td>
       <td class="center">hello2</td>
       <td class="center">hello3</td>
     </td>
   </table>

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!