Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Write a program that parses an URL address given in the format:
- and extracts from it the [protocol], [server] and [resource] elements. For example from the URL http://www.devbg.org/forum/index.php the following information should be extracted:
- [protocol] = "http"
- [server] = "www.devbg.org"
- [resource] = "/forum/index.php"
- */
- namespace EX12.ParsUrlAddress
- {
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- class ParsUrlAddress
- {
- static void Main()
- {
- string text = "mttp://www.devbg.org/forum/index.php";
- string pattern = @"(?<protocol>\A(\w*))*(?<server>www\w*(\.{1}\w*\.{1}\w*))*(?<resource>(\b/\w*)+.\w*)";
- Match match = Regex.Match(text, pattern);
- string protokol = match.Groups["protocol"].Value;
- string server = match.Groups["server"].Value;
- string resource = match.Groups["resource"].Value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement