Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. namespace HTTPProtocol_exercises___Validate_URL
  2. {
  3. using System;
  4. using System.Net;
  5. using System.Text.RegularExpressions;
  6.  
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. string input = WebUtility.UrlDecode(Console.ReadLine());
  12. Regex regexCheck = new Regex(@"(https|http):\/{2}([a-zA-Z0-9\.-]+)(\:\d+)?([\/][\w\W]+)");
  13. Match match = regexCheck.Match(input);
  14. string protocol = match.Groups[1].Value;
  15. string host = match.Groups[2].Value;
  16. string port = match.Groups[3].Value;
  17. string path = match.Groups[4].Value;
  18. string queryStrings = match.Groups[5].Value;
  19. string fragment = match.Groups[6].Value;
  20.  
  21. if (string.IsNullOrEmpty(protocol))
  22. {
  23. Console.WriteLine("Invalid URL");
  24. return;
  25. }
  26.  
  27. if (string.IsNullOrEmpty(host))
  28. {
  29. Console.WriteLine("Invalid URL");
  30. return;
  31. }
  32.  
  33. if (string.IsNullOrEmpty(port))
  34. {
  35. Console.WriteLine("Invalid URL");
  36. return;
  37. }
  38.  
  39. if (string.IsNullOrEmpty(path))
  40. {
  41. Console.WriteLine("Invalid URL");
  42. return;
  43. }
  44.  
  45. Console.WriteLine("Protocol: {0} \nHost: {1} \nPort: {2} \nPath: {3}", protocol, host, port, path);
  46.  
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement