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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:26:32+00:00 2026-05-17T23:26:32+00:00

I have several HTML blocks on a page set up like: <p class=something> <a

  • 0

I have several HTML blocks on a page set up like:

<p class="something">
    <a href="http://example.com/9999">text 1 2 3</a>
    <a href="http://example.com/2346saasdf">text 3 4 5</a>
    (9999)
    <a href="http://example.com/sad3ws">text 5 6 7random</a>
</p>

I want to get the digit that is in the parentheses, with them. I have to admit I’ve never really used regex before — read about it, seen examples of it but haven’t used it myself. Anyway, I created this with a little bit of looking around:

<p class="something">(.*?)</p>

That correctly gets the entire <p> block, but again, I just want the (9999) (with parentheses intact). I’m not really sure how to get it.

Assuming that other elements on the page could also have digits in parentheses (but they won’t be included in this exact format), and that the HTML will remain valid and consistent, how can I get it?

I understand this is probably easy for someone who has used regex before, but for the solution, I’d appreciate a little detail on what each character captures so I can learn from it.

  • 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-17T23:26:32+00:00Added an answer on May 17, 2026 at 11:26 pm

    Don’t use regex to parse HTML.

    Instead, use an HTML parser, then simply read the text (non-tag) content within the desired <p> block.

    jQuery is a pretty decent HTML parser, so you can get the desired text stored in a variable x using:

    var x = $('p').clone().find('a').remove().end().text();
    

    working example

    If you can’t use jQuery to make your life easy for whatever reason, you can use raw JavaScript at the DOM:

    var y = document.getElementsByTagName("p")[0].cloneNode(true);
    var x = "";
    for(var k in y.childNodes){ 
        if(y.childNodes[k].nodeType == 3){ 
            x += y.childNodes[k].textContent; 
        }
    }
    x = x.trim();
    

    working example

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

Sidebar

Related Questions

I have several like this in my HTML code: <input class=table type=checkbox name=interest[] value=finger
If I have a block of HTML like:- <div id=t1> <div> <input type=text value=Bla/>
I have a web page with several HTML Select controls that all allow multiple
I have a simple HTML page that rotates through several status pages that I
Say I have several inline-block div tags, like this <div class=image> </div> <div class=image>
On my website, I have several html files I do not link off the
i have several common elements (components), that will generate some html. it seems my
I have an HTML table with several columns and I need to implement a
I have several old 3.5in floppy disks that I would like to backup. My
I want to have several divs with content side-by-side like D1 D2 D3 D4

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.