Advertisement
soxa

EX12

Jan 17th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. /*Write a program that parses an URL address given in the format:
  2. 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:
  3. [protocol] = "http"
  4. [server] = "www.devbg.org"
  5. [resource] = "/forum/index.php"
  6. */
  7. namespace EX12.ParsUrlAddress
  8. {
  9.     using System;
  10.     using System.Text;
  11.     using System.Text.RegularExpressions;
  12.  
  13.     class ParsUrlAddress
  14.     {
  15.         static void Main()
  16.         {
  17.             string text = "mttp://www.devbg.org/forum/index.php";
  18.             string pattern = @"(?<protocol>\A(\w*))*(?<server>www\w*(\.{1}\w*\.{1}\w*))*(?<resource>(\b/\w*)+.\w*)";
  19.  
  20.             Match match = Regex.Match(text, pattern);
  21.  
  22.             string protokol = match.Groups["protocol"].Value;
  23.             string server = match.Groups["server"].Value;
  24.             string resource = match.Groups["resource"].Value;
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement