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

  • Home
  • SEARCH
  • 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 8612719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:41:49+00:00 2026-06-12T04:41:49+00:00

<tr><td align=right>Name:</td><td align=left><b><font color=black>Nathan</font></b></td></tr> <tr><td align=right>Extension:</td><td align=left><b>222</b></td></tr> I have the above HTML glob of

  • 0
<tr><td align=right>Name:</td><td align=left><b><font color=black>Nathan</font></b></td></tr>
<tr><td align=right>Extension:</td><td align=left><b>222</b></td></tr>

I have the above HTML glob of text (can’t be changed) and I’d like a regular expression that returns 3 capturing groups, the label (Name|Extension) the font color (black|red) and the data (\w+).

I’m having some trouble returning capture group 2, the font color. As you can see, it’s not present on the “Extension” row of the table, so I’ve made the capture group optional. When I do that, it’s not matching at all on the first row. I’ve tried fiddling a lot with trial and error of a bunch of different combinations of quantifiers, but I still can’t get the result I’m looking for.

Here’s the pattern I have so far: (Name|Extension):.*?(?:<font color=(black|red)>)?.*?>(\w+)

I believe the .*? is consuming what would be the optional capture group and only matching the 1st and 3rd group. If someone could explain to me where I’ve gone wrong, that would be great.

Edit: As someone who is trying to learn more about regular expressions, I would appreciate it if people could interpret the data I have above as immutable text rather than HTML.

  • 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-12T04:41:51+00:00Added an answer on June 12, 2026 at 4:41 am

    The problem is the reluctant quantifiers. The first .*? consumes nothing at first, allowing the next part of the regex to try matching the FONT tag right after the :. It doesn’t find one, but that’s okay because that part’s optional. Then the second .*? takes over, consuming only as much as it has to until the >(\w+) can match. So if there is a FONT tag, it’s getting matched by the second .*?, not by the optional group as you intended.

    But don’t bother making the quantifiers greedy; it might work, but more likely it will just fail less efficiently. Try this instead:

    <td[^>]*>(Name|Extension):</td><td[^>]*><b>(?:<font color=(black|red)>)?([^<]*)<
    

    Because I explicitly matched all the tags following the label, it’s in the correct position to match the FONT tag if there is one. If it’s there, group(2) will contain the color; otherwise it will be null.

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

Sidebar

Related Questions

Say I have this HTML fragment <td width=25% style=text-align:right; > <span style=font-family: Arial; font-size:
i have this <li><a href=# >title</a> <span style='text-align:right;'>(0)</span></li> its not working and this <li><a
I have seen questions posted on here asking how to left and right align
I am trying to align a part of text to the right and the
How to right align a string in 4gl with specified no.of spaces?
I want to right-align an inline element to the right of a div .
The most obvious way to right-align a Label in WinForms doesn't work: setting anchor
I am trying to right-align the output of some PL/SQL code, but dbms_output.put_line is
I'd like to right align this gridview so that it's flush against the right
How can I align the first column to the right and second column to

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.