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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:57:52+00:00 2026-05-16T22:57:52+00:00

I have a string and need a RegEx Pattern for this, so I can

  • 0

I have a string and need a RegEx Pattern for this, so I can extract only the date and the numbers from the tags:

Dim a as string= "<table id=table-1 > <tbody> <td align=right> <h2 id=date-one>12.09.2010</h2> </td> </tr> </tbody></table> <table id=table-2 border=0 cellspacing=0 cellpadding=0><tbody><tr><td align=center valign=middle><h3 id=nb-a>01</h3></td><td align=center valign=middle><h3 id=nb-a>>02</h3></td><td align=center valign=middle><h3 id=nb-a>03</h3></td></tr></tbody></table>"

This string will have more than one block of similar data …so I must be in loop …
Thank you!
Adrian

  • 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-16T22:57:52+00:00Added an answer on May 16, 2026 at 10:57 pm

    An html parser (e.g., the HtmlAgilityPack) will be simpler in the long term but as a guide to Regex here’s how to do it for your case:

      Dim pattern As String = "" 'what goes here?
      ' wrapping line for viewing, 
      ' imagine the following is a single line
      Dim a As String = 
         "<table id=table-1 > <tbody> <td align=right> 
         <h2 id=date-one>12.09.2010</h2> </td> </tr> </tbody></table> 
         <table id=table-2 border=0 cellspacing=0 cellpadding=0>
         <tbody><tr><td align=center valign=middle><h3 id=nb-a>01
         </h3></td><td align=center valign=middle><h3 id=nb-a>>02
         </h3></td><td align=center valign=middle><h3 id=nb-a>03</h3>
         </td></tr></tbody></table>"
      ' end of the a variable declaration
      For Each match As Match In Regex.Matches(a, pattern)
         Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
      Next
    

    Naively for the first attempt match any numbers:

    Dim pattern As String = "[\d]+"    ' \d matches any number,
                                       ' + specifies one or more
    

    This of course matches way too many items and does not match the date as a single group. In your case each match is inside a tag and so is preceeded by a ‘>’ and followed by a ‘<‘.

    Dim pattern As String = ">[.\d]+<" ' allow the '.' as well as numbers
                                       ' capture any string that starts with '>'
                                       ' followed by one or more numbers and '.'
                                       ' ending with '<'
    

    This unforturnately includes the ‘>’ and the ‘<‘ in your matches. Now we need positive lookbehind and positive lookahead:

    Dim pattern As String = "(?<=>)[.\d]+(?=<)" 
                                       ' (?<=regex) is positive lookbehind for regex
                                       ' (?=regex) is positive lookahead for regex
                                       ' capture any string after '>' 
                                       ' with by one or more numbers and '.'
                                       ' before '<'
    

    Now things are looking good because we’re only matching the date and three numbers! However, what if the date was separated by ‘-‘ or ‘/’ instead of ‘.’?

    Dim pattern As String = "(?<=>)[-/.\d]+(?=<)" 
                                       ' add '-' and '/' to date separators
    

    Easily handled. But what if there are spaces before or after the number or date within the element text?

    Dim pattern As String = "(?<=>\s*)[-/.\d]+(?=\s*<)"
                                       ' lookbehind regex is ">\s*" means match
                                       '    the char '>' 
                                       '    followed by 0 or more whitespace chars
                                       ' lookahead regex is "\s*<" means match
                                       '    0 or more whitespace chars
                                       '    followed by the char '<' 
    

    Not too bad. The only problem is that this method still takes more effort and breaks more easily than using an html parser to loop through all the elements, check if the element text is a valid number or date, and add the matching elements text to a list.

    Consider for example altering the Regex method to handle currencies (where “$100.03.45” should not match) or commas in numbers or ensuring that dates have exactly three groups, each with one, two, or four digits, where only one group can have four, and one of the two digit groups can not exceed 12, etc. Insanity lies down that road.

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

Sidebar

Related Questions

Hi have this URL string which I need to extract possibly using regex but
I can't figure this out. I need to extract the second level domain from
i have this pattern i using to replace string: var html = some test
I have a string like this that I need to parse into a 2D
I have an input string and a pattern. I need to replace each match
If I have HTML like this: <dsometext<f<legit></legit> whatever What regex pattern do I use
Need some regex help in Java. I have a string, which contains text and
I need to parse this string and extract bold number out od it .
I have 2 strings. and I need one Regex for both. s1=The 8481D provides
I need the regex to find function calls in strings in php, I have

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.