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 4029292
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:19:38+00:00 2026-05-20T11:19:38+00:00

Context The case is screen scraping web content using QuotaXML SDK 1.6 to finally

  • 0

Context
The case is screen scraping web content using QuotaXML SDK 1.6 to finally display the data on the dashboard and on the iPhone.
This QuotaXML tool offers regex for extracting table data only.
QuotaXML does parse html tables using a three step approach.
1. First it identifies the table, for example using “(?si)<table.*?>(.*?)</table>”
2. Second within this parsed table it identifies rows, like “(?si)<tr.*?>(.*?)</tr>”
3. Third within this row scope, individual cells are identified like “(?si)<tr.*?>(.*?)</tr>“

The problem
The source html contains some rows that are not relevant data like lines or images that span full table width using a colspan.
Or tables contain data cells which are not relevant to the data lines needed, like call detail records which also contain calls to freephones which are not substracted from the minutes in your plan, in this case 0800 and 00800 numbers.
In other words (.*?) may not match ‘ colspan=”‘ neither ‘>0800’ neither ‘>00800’.

In code:

exclude:<tr><td colspan="2"></td></tr>
include:<tr><td><strong>Date</strong></td><td><strong>Time</strong></td></tr>
exclude:<tr><td>05-01-2011</td><td>08004913</td></tr>
include:<tr><td>05-01-2011</td><td>0123456789</td></tr>

Homework done
Even trying my first (start simple) tries to only exclude colspan are all failing:

  1. (?si)<tr.*?>(?!colspan)(.*?)</tr>
  2. (?si)<tr.*?>(.*?)(?!colspan)</tr>
  3. (?si)<tr.*?>.*?[^colspan].*?</tr>
  4. (?si)<tr(\s[^>]*)?>.*?(?!colspan).*?</tr>
  5. (?si)<tr(\s[^>]*)?>.*?(!colspan).*?</tr>
  6. (?si)<tr(\s[^>]*)?>(.*?)(?!colspan)</tr>
  7. (?si)<tr.*?>^(?!.*?colspan=").*?</tr>
    How to negate specific word in regex? seems related though these suggestions don’t result in a match at all.
  8. (?si)<tr.*?>(.(?<!colspan))*?</tr>
  9. (?si)<tr.*?>(?!.*colspan).*</tr>
    Neither do give do positive and negative lookarounds using http://www.regular-expressions.info/lookaround.html the clue.

How should I correctly write this regex?

  • 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-05-20T11:19:38+00:00Added an answer on May 20, 2026 at 11:19 am

    The first problem you’re having is that your original expressions are very fragile, because of the “.*?>” intended to match everything up to the earliest “>” — but which will actually match to the following “>” if the rest of the expression fails and backtracks.

    Use a construct like “[^>]*>” instead.

    The second problem is that you’re misinterpreting the meaning of the negative lookahead: it’s not checking that the given pattern does not occur ahead of its position — it’s looking ahead of its position to check that the pattern does not occur AT THAT POSITION.

    With these two changes, your first attempt was very close to solving your test cases:

    $ pcretest
    PCRE version 7.8 2008-09-05
    
      re> /(?si)<tr[^>]*>(?!.*(colspan|>0?0800))(.*?)<\/tr>/
    data> <tr><td colspan="2"></td></tr>
    No match
    data> <tr><td><strong>Date</strong></td><td><strong>Time</strong></td></tr>
     0: <tr><td><strong>Date</strong></td><td><strong>Time</strong></td></tr>
     1: <unset>
     2: <td><strong>Date</strong></td><td><strong>Time</strong></td>
    data> <tr><td>05-01-2011</td><td>08004913</td></tr>
    No match
    data> <tr><td>05-01-2011</td><td>0123456789</td></tr>
     0: <tr><td>05-01-2011</td><td>0123456789</td></tr>
     1: <unset>
     2: <td>05-01-2011</td><td>0123456789</td>
    

    Note this will still fail to solve the whole problem because the presence of a “colspan” or 800 number later in the string will block the match. You need further test cases, such as:

    $ pcretest
    PCRE version 7.8 2008-09-05
    
      re> /(?si)<tr[^>]*>(?!.*(colspan|>0?0800))(.*?)<\/tr>/
    data> <tr><td>05-01-2011</td><td>0123456789</td></tr><tr><td colspan="2"></td></tr>
    No match
    

    So you need to ensure that the negative lookahead never crosses to the next :

    $ pcretest
    PCRE version 7.8 2008-09-05
    
      re> /(?si)<tr[^>]*>(?!((?!<\/tr).)*(colspan|>0?0800))(.*?)<\/tr>/
    data> <tr><td colspan="2"></td></tr>
    No match
    data> <tr><td><strong>Date</strong></td><td><strong>Time</strong></td></tr>
     0: <tr><td><strong>Date</strong></td><td><strong>Time</strong></td></tr>
     1: <unset>
     2: <unset>
     3: <td><strong>Date</strong></td><td><strong>Time</strong></td>
    data> <tr><td>05-01-2011</td><td>08004913</td></tr>
    No match
    data> <tr><td>05-01-2011</td><td>0123456789</td></tr>
     0: <tr><td>05-01-2011</td><td>0123456789</td></tr>
     1: <unset>
     2: <unset>
     3: <td>05-01-2011</td><td>0123456789</td>
    data> <tr><td>05-01-2011</td><td>0123456789</td></tr><tr><td colspan="2"></td></tr>
     0: <tr><td>05-01-2011</td><td>0123456789</td></tr>
     1: <unset>
     2: <unset>
     3: <td>05-01-2011</td><td>0123456789</td>
    

    At which point one may wonder whether RegExps are the right tool for this particular problem 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When screen-scraping, what are the gotchas to look out for? The inspiration for this
I'm using OpenGL ES in my iPhone application and sometimes during startup the screen
Some context upfront: Imagine a 200+ developers company finally setting up a more or
Some context: one of the systems I'm working on is a .net 2.0 web
I have an app using a ListView as a main screen. Each row displays
Context: I'm in charge of running a service written in .NET. Proprietary application. It
Context: So, I am attempting to build a ridiculously complex domain model. Talking with
Context: I have a WPF App that uses certain unmanaged DLLs in the D:\WordAutomation\MyApp_Source\Executables\MyApp
Context : programming a c/c++ win32-mfc library How to know whether we are in
Context PHP 5.3.x Overview After doing a code-review with an associate who uses both

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.