Pls. Help me to improve this regex ( Extracting Url )

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
<pre> foo://example.com:8042/over/there?name=ferret#nose
___/ ____________________/___________/_______________/ ____/<br/>

scheme_____authority_________path_______query_______fragment[/code]

I have found a regex for extracking url from internet.

Its: string stRegex = "(?<protocol>http(s)?|ftp)://(?<server>([A-Za-z0-9-]+\.)*(?<basedomain>[A-Za-z0-9-]+\.[A-Za-z0-9]+))+((:)?(?<port>[0-9]+)?(/?)(?<path>(?<dir>[A-Za-z0-9\._\-]+)(/){0,1}[A-Za-z0-9.-/]*)){0,1}";

and i am using it with this way:
<br/>
Regex reg1 = new Regex(stRegex);<br/>
<br/>
MatchCollection myMatchCollection = reg1.Matches(string);<br/>
<br/>
foreach (Match myMatch in myMatchCollection)
{<br/>
myMatch.Groups["server"].Value.....
.....
<br/>
}
It has protocol, server, basedomain, port, path and dir properties. I want to add query and fragment properties. Can smo help me .
Thnx.

View the full article
 
Back
Top