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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:24:09+00:00 2026-05-23T11:24:09+00:00

I need a regular expression in C# for anchor tag in html source codes

  • 0

I need a regular expression in C# for anchor tag in html source codes as general as it’s possible. Consider this html code:

<a id="[constant]"
      href="[specific]"
    >GlobalPlatform Card Specification 2.2
    March, 2006</a>

By [constant] I mean the value is a constant string so there is no problem with it. By [specific] I mean the address is a simple and specific string so the regular expression for it, is simple. The main problem is that I can not handle the newline character in the middle of title of anchor tag. I wrote this regular expression previously that works well except handling the newline character between title of anchor tag.

<a[\\s\\n\\r]+id=\"[constant]"[\\s\\n\\r]+href=\"[specific]"[\\s\\n\\r]*>[\\s\\n\\r]*[^\\n\\r]+[\\s\\n\\r]*</a>

Please help me

  • 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-23T11:24:10+00:00Added an answer on May 23, 2026 at 11:24 am

    You should stay away from regular expressions when it comes to parse HTML and use an HTML parser like the HTML Agility Pack.

    And to help you get started check how simple it can be to parse that single anchor tag.

    HtmlDocument doc = new HtmlDocument();
    
    doc.LoadHtml(@"<a id=""[constant]""
          href=""[specific]""
        >GlobalPlatform Card Specification 2.2
        March, 2006</a>
    ");
    
    var anchor = doc.DocumentNode.Element("a");
    
    Console.WriteLine(anchor.Id);
    Console.WriteLine(anchor.Attributes["href"].Value);
    

    Beats regular expressions, don’t you think? 🙂

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

Sidebar

Related Questions

Possible Duplicate: I'm looking for a regular expression to remove a given (x)HTML tag
I need a regular expression to find out whether or not a h1 tag
I need regular expression that converts links in plain text to HTML links. Here
I need a regular expression that matches APA format references. I currently have this:
I need a regular expression to match this URL to enable URL rewriting. http://www.somewhere.com/index.php?route=common/home
I need a regular expression pattern to only accept positive whole numbers. It can
i need a Regular Expression to convert a a string to a link.i wrote
I need a regular expression to select all the text between two outer brackets.
I need an regular expression which matches the following: 'test foo bar, test' =>
I need a regular expression able to match everything but a string starting with

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.