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

The Archive Base Latest Questions

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

string content= <br /><br /><a href=need to replace this url>Cooking School</a><br /><br /><a href=http://www.sdlm.com>Feed

  • 0
string content=" 
        <br /><br /><a href="need to replace this url">Cooking School</a><br /><br /><a href="http://www.sdlm.com">Feed your senses</a><br /><br /><a href="http://www.sdl.com">Take your cooking skills to the next level. Find a cooking school near you!</a><br /><br /><a href="http:google.com"><img src="http://www.sdlm1.com/autd3umrl_u_t.jpg" /></a>
     "

I need to replace all anchor tags href value with different urls
I used the following function but its getting error

 public List<string> GetLinksFromHtml(string content)
        {
            string regex = @"<(?<Tag_Name>(a)|img)\b[^>]*?\b(?<URL_Type>(?(1)href|src))\s*=\s*(?:""(?<URL>(?:\\""|[^""])*)""|'(?<URL>(?:\\'|[^'])*)'))";
            var matches = Regex.Matches(content, regex, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var links = new List<string>();

            foreach (Match item in matches)
            {
                string link = item.Groups[1].Value;
                links.Add(link);
            }

            return links;
        }

Thanks for any help

  • 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-12T22:38:42+00:00Added an answer on June 12, 2026 at 10:38 pm

    Trying to parse html with regex is not a good idea. See this post. Use a real html parser like HtmlAgilityPack .

    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(content);
    foreach (var a in doc.DocumentNode.Descendants("a"))
    {
        a.Attributes["href"].Value = "http://a.com?url=" + HttpUtility.UrlEncode(a.Attributes["href"].Value);
    }
    
    var newContent = doc.DocumentNode.OuterHtml;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get the last string from a URL for example... http://www.mywebsite/blog/this-post I
I need to get the last string content of the url between / and
I am able to replace a word in a string content using the following
http://www.queness.com/post/328/a-simple-ajax-driven-website-with-jqueryphp I'm trying to get the above script to work, but with some changes.
I am using this function public static IList<Item> ParseAtom(string url) { try { XDocument
I have links like http://example.com?query1=query1&query2=query2 as href of anchor tag. I want to do
Is it possible to extract the string content of a specific line in a
I want to add large string content to a container dynamically. There are 60
I have an example json as below: { Passwd:String content, Userme:String content } how
I have the following class: private class NodeTemp { public string Content; public NodeTemp

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.