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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:27:25+00:00 2026-05-22T21:27:25+00:00

I am parsing a webpage for http links by first parsing out all the

  • 0

I am parsing a webpage for http links by first parsing out all the anchored tags, then parsing out the href tags, then running a regex to remove all tags that aren’t independent links (like href=”/img/link.php”). The following code works correctly, but also appends lots of blank lines in between the parsed links.

while (parse.ParseNext("a", out tag))
{
    string value;
    //A REGEX value, this one finds proper http address'
    Regex regexObj = new Regex(@"^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$");
    if (tag.Attributes.TryGetValue("href", out value))
    {
        string value2;
        //Start finding matches...
        Match matchResults = regexObj.Match(value);
        value2 = matchResults.Value;
            lstPages.AppendText(value2 + "\r\n");                        
    }
}

To fix this, I added the following code and it works to clean up the list:

if (value2 != "")
{
    lstPages.AppendText(value2 + "\r\n");
}

However, I

  1. Don’t believe this is the most efficient way to go about this and
  2. Still don’t understand where the != "" lines come from.

My actual question is on both of these but more for issue #2, as I would like to learn why I receive these results, but also if there is a more efficient method for this.

  • 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-22T21:27:26+00:00Added an answer on May 22, 2026 at 9:27 pm

    The reason you are getting an empty string in value2 is that matchResults.Value == "" if the regular expression fails to match. Instead of checking if value2 != "", you could directly check matchResults.Success to see if the regular expression matched. You’re basically doing that, anyway, since your particular regular expression would never match an empty string, but checking matchResults.Success would be more straightforward.

    Another thing to consider is that it’s not necessary to create the Regex object every iteration of your loop. Here are the modifications I suggest:

    //A REGEX value, this one finds proper http address'
    Regex regexObj = new Regex(@"^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$");
    while (parse.ParseNext("a", out tag))
    {
        string value;
    
        if (tag.Attributes.TryGetValue("href", out value))
        {
            string value2;
            //Start finding matches...
            Match matchResult = regexObj.Match(value);
            if (matchResult.Success)
            {
                value2 = matchResult.Value;
                lstPages.AppendText(value2 + "\r\n");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing some links on a webpage and then testing if these links exist
Ok, I have a very frustrating problem. I am parsing a webpage and need
Im parsing the source of a website and Im using this regex: /page\.php\?id\=([0-9]*)\\>(.*)\<\/a\>\<\/span\>/.match(self.agent.page.content) self.agent.page.content
I'm making an android program that retrieves content of a webpage using HttpURLConnection. I'm
I have a webpage that displays data based on a default date. The user
I'm trying to develop an agent/client that will listen to HTTP requests on a
I am developing a webpage in that the user can download their Resume for
I have an instance method, and within it, I did a simple webpage parsing:
I have a script that parses certain elements from a webpage and stores them
Is there any way in which I can download all the first visits to

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.