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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:24:31+00:00 2026-05-14T00:24:31+00:00

I have a string of text that contains html, and I need to extract

  • 0

I have a string of text that contains html, and I need to extract each url (most likely in img or a tags) to create a generic list of string objects. I only want the urls from inside html tags, not in the text. Is there an easy way to do this or will I have to resort to regular expressions?

If I have to resort to regular expressions, would you mind helping me out with that as well? 🙂

UPDATE:
To answer Seph, the input will be standard html.

<p>This is some html text.  my favourite website is <a href="http://www.google.com">google</a> and my favourite help site is <a href="http://www.stackoverflow.com">stackoverflow</a> and i check my email at <a href="http://www.gmail.com">gmail</a>.  the url to my site is http://www.example.com.   <img src="http://www.example.com/someimage.jpg" alt=""/></p>

And I want

  • http://www.google.com
  • http://www.stackoverflow.com
  • http://www.gmail.com
  • http://www.example.com/someimage.jpg

the end result should be All urls in any html tag, ignoring those are are "plain text"

UPPERDATE
Although he deleted his answer, I want to thank Jerry Bullard for bringing to my attention
Regex Buddy (http://www.regexbuddy). I wanted to upvote your answer but its gone. Bring it back and you get a vote!

  • 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-14T00:24:31+00:00Added an answer on May 14, 2026 at 12:24 am

    Something like this should help:

        private List<string> GetUrlStrings(string text)
        {
            List<string> listURL = new List<string>();
            Regex regex = new Regex("href\\s*=\\s*(?:(?:\\\"(?<url>[^\\\"]*)\\\")|(?<url>[^\\s]* ))");
            MatchCollection mathColl = regex.Matches(text);
    
            foreach (Match match in mathColl)
            {
                foreach (Group group in match.Groups)
                {
                    if (!group.Value.StartsWith("href")) // workaround regex issue
                    {
                        listURL.Add(group.Value);
                    }
                }
            }
            return listURL;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML string that contains text and images, e.g. <p>...</p> <img src=...
I have a string of text that contains html with all different types of
I have a long string of HTML that contains <p> <img> <span> and a
I have a string variable that contains the following html data: <p> <em><strong>This is
I have a variable that contains some text, some html, basically can be a
I have a Ruby hash that contains a user-generated string. I need to pass
I have a text file that contains some strings separated by ,. Strings are
I have a text string that has been doctored to be web safe URLs
I have a method that looks like this: public static String escape(String text) {
I have a arbitrarily large string of text from the user that needs 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.