Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- class URLParser
- {
- static void Main()
- {
- string input = Console.ReadLine();
- string pattern = @"(www|http|https|ftp)(\.|:\/\/)([a-z]+.[a-z]+.[a-z]+)(\/?)((.?)+)";
- Regex regex = new Regex(pattern);
- Match matcher = regex.Match(input);
- string www = matcher.Groups[1].ToString();
- //string protocol = "";
- //string server = "";
- //string resource = "";
- if (www.Equals("www"))
- {
- Console.WriteLine("[protocol] = \"\"");
- Console.WriteLine("[server] = \"{0}\"", input);
- Console.WriteLine("[resource] = \"\"");
- }
- else
- {
- Console.WriteLine("[protocol] = \"{0}\"", matcher.Groups[1]);
- Console.WriteLine("[server] = \"{0}\"", matcher.Groups[3]);
- Console.WriteLine("[resource] = \"{0}\"", matcher.Groups[5]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment