Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8178757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:50:31+00:00 2026-06-06T23:50:31+00:00

Ok to start I know i should not be using Regex to parse HTML

  • 0

Ok to start I know i should not be using Regex to parse HTML as it’s not very reliable, not 100% safe, etc. However, this is just a learning excercise for regex as much as anything else.

So my example uses the bbc website http://www.bbc.co.uk/sport/football/premier-league/table.

The project is parsing the tbody of the first table. I am trying to do a search so that only the elements matching a search value are returned. For example, given the search “manc” i would want the tr tag for manchester city and manchester united (matched from the url).

What i have so far is <tr\b[^>]*>(.*?)manc(.*?)</tr> however this matches from the first tr to the closing tr after man city and then returns the expected result for man utd. Could anyone point out where i’ve gone wrong with this regex.

Edit: Source (Trimmed)

<tbody id="trc-20-118996114-3">
  <tr id="team-138824012" class="team first">
    <td class="statistics"></td>
    <td class='position'>
      <span class='moving-up'>Moving up</span>
      <span class='position-number'>1</span>
    </td>
    <td class="team-name">
      <a href='http://www.bbc.co.uk/sport/football/teams/arsenal'>Arsenal</a>
    </td>
    <td class="played">0</td>

    <td class="home-won">
      <span>0</span>
    </td>
    <td class="home-drawn">0</td>
    <td class="home-lost">0</td>
    <td class="home-for">0</td>
    <td class="home-against">0</td>
    <td class="away-won">
      <span>0</span>
    </td>
    <td class="away-drawn">0</td>
    <td class="away-lost">0</td>
    <td class="away-for">0</td>
    <td class="away-against">0</td>
    <td class="goal-difference">0</td>
    <td class="points">0</td>
    <td class="last-10-games">
      <ol>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win last" title="Win">
          <span>Win</span>
        </li>
      </ol>
    </td>
    <td class="status">
      <a class="report" href="http://www.bbc.co.uk/sport/0/football/17973141">Report</a>
    </td>
  </tr>
  <tr id="team-137316633" class="team">
    <td class="statistics"></td>
    <td class='position'>
      <span class='moving-up'>Moving up</span>
      <span class='position-number'>2</span>
    </td>
    <td class="team-name">
      <a href='http://www.bbc.co.uk/sport/football/teams/aston-villa'>Aston Villa</a>
    </td>
    <td class="played">0</td>

    <td class="home-won">
      <span>0</span>
    </td>
    <td class="home-drawn">0</td>
    <td class="home-lost">0</td>
    <td class="home-for">0</td>
    <td class="home-against">0</td>
    <td class="away-won">
      <span>0</span>
    </td>
    <td class="away-drawn">0</td>
    <td class="away-lost">0</td>
    <td class="away-for">0</td>
    <td class="away-against">0</td>
    <td class="goal-difference">0</td>
    <td class="points">0</td>
    <td class="last-10-games">
      <ol>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="loss last" title="Loss">
          <span>Loss</span>
        </li>
      </ol>
    </td>
    <td class="status">
      <a class="report" href="http://www.bbc.co.uk/sport/0/football/17973120">Report</a>
    </td>
  </tr>
  <tr id="team-137318151" class="team">
    <td class="statistics"></td>
    <td class='position'>
      <span class='moving-down'>Moving down</span>
      <span class='position-number'>7</span>
    </td>
    <td class="team-name">
      <a href='http://www.bbc.co.uk/sport/football/teams/manchester-city'>Man City</a>
    </td>
    <td class="played">0</td>

    <td class="home-won">
      <span>0</span>
    </td>
    <td class="home-drawn">0</td>
    <td class="home-lost">0</td>
    <td class="home-for">0</td>
    <td class="home-against">0</td>
    <td class="away-won">
      <span>0</span>
    </td>
    <td class="away-drawn">0</td>
    <td class="away-lost">0</td>
    <td class="away-for">0</td>
    <td class="away-against">0</td>
    <td class="goal-difference">0</td>
    <td class="points">0</td>
    <td class="last-10-games">
      <ol>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="win last" title="Win">
          <span>Win</span>
        </li>
      </ol>
    </td>
    <td class="status">
      <a class="report" href="http://www.bbc.co.uk/sport/0/football/17973148">Report</a>
    </td>
  </tr>
  <tr id="team-137318152" class="team">
    <td class="statistics"></td>
    <td class='position'>
      <span class='moving-down'>Moving down</span>
      <span class='position-number'>8</span>
    </td>
    <td class="team-name">
      <a href='http://www.bbc.co.uk/sport/football/teams/manchester-united'>Man Utd</a>
    </td>
    <td class="played">0</td>

    <td class="home-won">
      <span>0</span>
    </td>
    <td class="home-drawn">0</td>
    <td class="home-lost">0</td>
    <td class="home-for">0</td>
    <td class="home-against">0</td>
    <td class="away-won">
      <span>0</span>
    </td>
    <td class="away-drawn">0</td>
    <td class="away-lost">0</td>
    <td class="away-for">0</td>
    <td class="away-against">0</td>
    <td class="goal-difference">0</td>
    <td class="points">0</td>
    <td class="last-10-games">
      <ol>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="draw" title="Draw">
          <span>Draw</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="loss" title="Loss">
          <span>Loss</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win" title="Win">
          <span>Win</span>
        </li>
        <li class="win last" title="Win">
          <span>Win</span>
        </li>
      </ol>
    </td>
    <td class="status">
      <a class="report" href="http://www.bbc.co.uk/sport/0/football/17973162">Report</a>
    </td>
  </tr>
</tbody>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:50:32+00:00Added an answer on June 6, 2026 at 11:50 pm

    The problem is, your regular expression is too broad. Look what you’re asking for:

    <tr\b[^>]*>(.*?)manc(.*?)</tr>
    

    Lets simplify it a little bit.

    <tr>.*?manc.*?</tr>
    

    So you’re saying, ok. I need to match a tr followed by anything and then manc and then ANYTHING and then a closing tr. So. Of course what happens is the regex starts at the first tr and goes ok. I’ve got a tr let me keep matching until I find manc. In the meantime, you probably just passed a bunch of other tr. But your regex doesn’t care.

    Try this:

    <tr>(?:(?!</tr>).)*manc.+?</tr>
    

    Or, I guess in your example:

    <tr\b[^>]*>(?:(?!</tr>).)*manc.+?</tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I start, I should let you know that I'm hardly experienced in PHP.
Before I start know this: I am extremely new to Java and programming. How
1) I know the start point of the arrow and I know the endpoint.
if you know the start and end positions in string from where to begin
I know that when I use range([start], stop[, step]) or slice([start], stop[, step]) ,
I know VS2012 has the ability to start the Windows Simulator right out of
I know that we can start new activity with the steps as follows :
I already know how to start a one new activity when you click a
I know that if i have rootViewController that start with tabBar i can create
Possible Duplicate: How to know if Process.Start() is successful? I have a process similar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.