Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi, need help for a regular expression, cant really figure ir out myself.
I have a website, for example http://www.website.com and I use this code to read the content of the website.
 
 StreamReader webSource = new StreamReader(webResponse.GetResponseStream());
 
                    string source = webSource.ReadToEnd();
So I need a regular expression match to find all the containig website url`s that are within the server. So I need to find all theese kind of links:
 
http://www.website.com/search/84f2fbfcf85129866221a71b7d48f2da/?sCat=124");
http://www.website.com/search/7569ac370abc2aa02cd3e0760c418cc9/?sCat=38");
http://www.website.com/show/?i=2368173&popup=1mp;search=bcc6928a29fe348a30cbfc2dc1aba4ab&place=1");
 
And i dont want to find links like
http://www.OTHERwebsite.com/search/84f2fbfcf85129866221a71b7d48f2da/?sCat=124&
Can anyone help with this?
Posted 26-Dec-12 9:15am
Comments
Zoltán Zörgő at 26-Dec-12 15:21pm
   
- "url`s that are within the server" makes no sense, since you fetch only a single page, without references.
- you havce specified only absolute urls. You don't need the relative ones?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I get a syntax error somehow
 
foreach (Match n in Regex.Matches(source, @(["'])(http://www.website.com/.*?)\1"))
                    {
 
?
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 6-Nov-13 12:10pm
   
Please don't post non-answers as "Solution", it is considered as abuse. You can only get down-votes and abuse reports. Use comments or "Improve question".
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This will find what you have specified:
(["'])(http://www.website.com/.*?)\1
More exactly it will search for it between matching single or double quotes. Group 2 will contain the url.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,609
1 Sergey Alexandrovich Kryukov 6,240
2 CPallini 5,180
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100