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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:44:08+00:00 2026-05-23T09:44:08+00:00

I am trying to extract a specific tag from html (I know from reading

  • 0

I am trying to extract a specific tag from html (I know from reading on this site that you should not try and parse html with regular expressions, but I only need specific tags, that follows a pretty specific order)

This is the regular expression (tested in Expresso) and working perfectly as it should

(?<ExternalSource2>\<eds2[\s.]+url\=\"?(?<Url>[\w\./:\?=&\+%\d_-]+)\"?[\s.]*\>(?<Text>[\s.]*[\w\s\d]*)\</eds2\>)

The problem comes when trying to use this in C# this code

Regex re = new Regex(@"(?<ExternalSource2>\<eds2[\s.]+url\=\""?(?<Url>[\w\./:\?=&\+%\d_-]+)\""?[\s.]*\>(?<Text>[\s.]*[\w\s\d]*)\</eds2\>)");

        string Input = @"width: 662px; height: 60px; vertical-align: middle""><eds2 url=""http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147"">PlaceLogo</eds2></td></tr></tbody></table><table style=""width: 662px; border-collapse: collapse""><tbod";

        foreach (Match m in re.Matches(Input)) {
            HttpContext.Current.Response.Write(string.Format("Match : {0}<br/>", m));
            short i = 0;
            foreach (Group g in m.Groups) {
                HttpContext.Current.Response.Write(string.Format("Group {0} = {1}<br/>", i++, g.Value));
            }
            HttpContext.Current.Response.Write("<br/><br/>");
        }

Produces this result :

Match : PlaceLogo
Group 0 = PlaceLogo
Group 1 = PlaceLogo
Group 2 = http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147
Group 3 = PlaceLogo

which is not at all what I expect.

When you use the code below though, the result is more what I would expect (but still not quite) :

    Regex re = new Regex(@"eds2[\s.]+url\=\""?(?<Url>[\w\./:\?=&\+%\d_-]+)\""?[\s.]*\>(?<Text>[\s.]*[\w\s\d]*)\</eds2\>");

Result :

Match : eds2 url="http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147">PlaceLogo
Group 0 = eds2 url="http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147">PlaceLogo
Group 1 = http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147
Group 2 = PlaceLogo

The expected output is :

Match : <eds2 url="http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147">PlaceLogo</eds2>

Group 0 = <eds2 url="http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147">PlaceLogo</eds2>

Group 1 = <eds2 url="http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147">PlaceLogo</eds2>

Group 2 = http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147

Group 3 = PlaceLogo

Any help appreciated.

  • 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-23T09:44:08+00:00Added an answer on May 23, 2026 at 9:44 am

    I can’t reproduce your problem with your sample code. It creates the following output:

    Match : <eds2 url="http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147">PlaceLogo</eds2>
    
    Group 0 = <eds2 url="http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147">PlaceLogo</eds2>
    
    Group 1 = <eds2 url="http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147">PlaceLogo</eds2>
    
    Group 2 = http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147
    
    Group 3 = PlaceLogo
    

    Please clarify your question.

    UPDATE:
    I guess, your problem is the following:
    You write the result of the match directly to your response stream without escaping it. This means, it will be interpreted as HTML and not as text, as you want.
    You should change your code to this:

    Regex re = new Regex(@"(?<ExternalSource2>\<eds2[\s.]+url\=\""?(?<Url>[\w\./:\?=&\+%\d_-]+)\""?[\s.]*\>(?<Text>[\s.]*[\w\s\d]*)\</eds2\>)");
    
    string Input = @"width: 662px; height: 60px; vertical-align: middle""><eds2 url=""http://www.someurl.co.uk/_modules/system/Newsletter.aspx?Username=TBO&Password=N5TBO2&TagID=PlaceLogo&TownID=147"">PlaceLogo</eds2></td></tr></tbody></table><table style=""width: 662px; border-collapse: collapse""><tbod";
    
    foreach (Match m in re.Matches(Input))
    {
        HttpContext.Current.Response.Write(string.Format("Match : {0}<br/>",
                                                         Server.HtmlEncode(m)));
        short i = 0;
        foreach (Group g in m.Groups)
        {
            HttpContext.Current.Response
                               .Write(string.Format("Group {0} = {1}<br/>", i++, 
                                                    Server.HtmlEncode(g.Value)));
        }
        HttpContext.Current.Response.Write("<br/><br/>");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extract some specific pictures from html content . Currently I have
I am trying to extract a word that matches a specific pattern from various
I am trying to extract specific content(links, text, images) from an HTML page. Is
I am trying to extract the text between that has specific text file: ----
Trying to extract strings that are wrapped in double brackets. For example [[this is
I'm trying to extract specific fields from my file. Basically, output fields only containing
I am trying to extract the palette from a 5-6-5 (16bit) bitmap image that
I'm trying to parse an html output file from a program called mirdeep. I
I am trying to process some PHP code to extract keys from a specific
I am trying to extract a specific url pattern from the body of some

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.