Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

Regular Expression Blues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian - 02 Sep 2007 15:31 GMT
I need a regular expression that will give me a List<string> of all URLs it
finds within a piece of text I provide.  I know that all of the URLs will
begin with something like:
https://www.somesite.com/

I really stink at RegEx - can someone help me out?  I'm also not sure how to
have it actually return a List...

TIA
Brian
UL-Tomten - 02 Sep 2007 18:22 GMT
> I really stink at RegEx - can someone help me out?

You're in luck! Regular expression tutorials is the second most common
type of web site on the Internet.

> I'm also not sure how to have it actually return a List...

It won't; you'll have to construct the list yourself, along the lines
of:

           List<string> l = new List<string>();
           foreach (Match m in Regex.Matches(s, "http://[0-9?&a-z-_./]
+", RegexOptions.Singleline)) {
               l.Add(m.Value);
           }

This uses the static method Regex.Matches, which essentially
constructs a RegEx instance and discards it after finding the matches.
You might want to reuse the RegEx instance for performance reasons.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.