Advertisement
JouJoy

Regular

Mar 29th, 2022
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.14 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Text.RegularExpressions;
  8.  
  9. //public class Ex1
  10. //{
  11. //    public static void Main()
  12. //    {
  13. //        int count = 0;
  14. //        //string pattern = @"((^0)(?!\.))      (\((\d*[1-9]+\d*)\))    (^[\+-]?(0(?=\.)|[1-9]\d*)      (\.((?(0+(?=[1-9]*))(?=[1-9]*))|([1-9]+)|([1-9]+)$)+(\((\d*[1-9]+\d*)\))?$)?
  15. //        string pattern = @"((^[\+-]?(0(?=\.)|[1-9]\d*)(\.(((0+)(?=[1-9]+))|([1-9]+)|(0+)(?=\())+(\((\d*[1-9]+\d*)\))?)$)|((^0)(?!\.))|(^[\+-]?(^(0)$|[1-9]\d*$)))";
  16. //        //string[] names = { "0.0(64)5", "-0.5", "0.5(1001010)", "3.75000001","0.0000000","2", "+0..56", "-0", "1000"};
  17. //        string[] names = {".9", "1.5", "0", "-6", "-0.5", "+2", "0.0(64)", "-0.5", "0.5(1001010)", "-0", "0.(35)00", "-3.75hjbykfjh", "0.0(64)5", "-0.5", "0.5(1001010)", "3.75000001", "0.0000000", "2", "+0..56", "-0", "1000" };
  18. //        foreach (string name in names)
  19. //        {
  20. //            if (Regex.IsMatch(name, pattern))
  21. //            {
  22. //                Console.WriteLine(Regex.Match(name, pattern));
  23. //                count++;
  24. //            }
  25. //        }
  26. //        Console.WriteLine(count);
  27. //    }
  28. //}
  29.  
  30. //public class Ex2
  31. //{
  32. //    public static void Main()
  33. //    {
  34. //        string pattern = "^(0+|1+|((01)+0?)|((10)+1?))$";
  35. //        string[] names = { "11111", "10001", "10101", "00001","0000","01010011011" };
  36. //        foreach (string name in names)
  37. //            Console.WriteLine(Regex.Match(name, pattern));
  38. //    }
  39. //}
  40.  
  41. //public class Ex3
  42. //{
  43. //    public static void Main()
  44. //    {
  45. //        Random x = new Random();
  46. //        string pattern = @"^\d*[02468]$";
  47. //        Regex rgx = new Regex(pattern);
  48. //        int count = 0;
  49. //        int count2 = 0;
  50. //        while (count2 < 10)
  51. //        {
  52. //            int n = x.Next(1, 1000);
  53. //            string s = n.ToString();
  54. //            if (rgx.IsMatch(s))
  55. //            {
  56. //                count2++;
  57. //                Console.Write(s + "\n");
  58. //            }
  59. //            count++;
  60. //        }
  61. //        Console.Write("count = " + count + "\n");
  62. //    }
  63. //}
  64.  
  65. //public class Ex4
  66. //{
  67. //    public static void Main()
  68. //    {
  69. //        Random x = new Random();
  70. //        string pattern = @"^[13579]*[02468]{0,2}[13579]*$";
  71. //        Regex rgx = new Regex(pattern);
  72. //        int count = 0;
  73. //        int count2 = 0;
  74. //        while (count2 < 10)
  75. //        {
  76. //            int n = x.Next(1, 1000000);
  77. //            string s = n.ToString();
  78. //            if (rgx.IsMatch(s))
  79. //            {
  80. //                count2++;
  81. //                Console.Write(s + "\n");
  82. //            }
  83. //            count++;
  84. //        }
  85. //        Console.Write("count = " + count + "\n");
  86. //    }
  87. //}
  88.  
  89. //public class Ex5
  90. //{
  91. //    public static void Main()
  92. //    {
  93. //        Random x = new Random();
  94. //        string pattern = @"^[02468]{4,5}$";
  95. //        Regex rgx = new Regex(pattern);
  96. //        int count = 0;
  97. //        int count2 = 0;
  98. //        while (count2 < 10)
  99. //        {
  100. //            int n = x.Next(1, 1000000);
  101. //            string s = n.ToString();
  102. //            if (rgx.IsMatch(s))
  103. //            {
  104. //                count2++;
  105. //                Console.Write(s + "\n");
  106. //            }
  107. //            count++;
  108. //        }
  109. //        Console.Write("count = " + count + "\n");
  110. //    }
  111. //}
  112.  
  113. //public class Ex6
  114. //{
  115. //    public static void Main()
  116. //    {
  117. //        Random x = new Random();
  118. //        string pattern = @"^\d*[02468]{2}\d*[02468]{2}\d*$";
  119. //        Regex rgx = new Regex(pattern);
  120. //        int count = 0;
  121. //        int count2 = 0;
  122. //        while (count2 < 10)
  123. //        {
  124. //            int n = x.Next(1, 1000000);
  125. //            string s = n.ToString();
  126. //            if (rgx.IsMatch(s))
  127. //            {
  128. //                count2++;
  129. //                Console.Write(s + "\n");
  130. //            }
  131. //            count++;
  132. //        }
  133. //        Console.Write("count = " + count + "\n");
  134. //    }
  135. //}
  136.  
  137.  
  138.  
  139. //пароль[A - Za - z0 - 9_\.\!#\*\?\-\+,]{8,17}
  140. //email([\w\.\😏 +@[\w] + (\.com)| (\.ru)| (\.org))
  141. //телефон(((\+7) | 8 |)?[0 - 9]
  142. //{ 10})
  143. //public static void Main()
  144. //{
  145. //    string pattern = @" ";
  146. //    string[] names = { " " };
  147. //    foreach (string name in names)
  148. //        Console.WriteLine(Regex.Match(name, pattern));
  149. //}
  150.  
  151.  
  152. //public class Ex7
  153. //{
  154. //    public static void Main()
  155. //    {
  156. //        //string pattern = @"^((0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](1(2[3-9][7-9]|[3-8][0-9][0-9]|9[0-7][0-7]))\s([0-1]\d|2[0-3])(:[0-5]\d))|((((0[6-9]|[12][0-9]|3[01])[/](03))|((0[1-9]|[12][0-9]|3[01])[/](0[4-9]|1[012])))[/](1237)\s(1[2-9]|2[0-3])(:[0-5]\d))$|((((0[1-9]|1[0-9]|2[0-7])[/](02))|((0[1-9]|[12][0-9]|3[01])[/](01)))[/](1978)\s([0-1]\d|2[01])(:(([0-2]\d)|(3[0-5]))))$";
  157. //        //string pattern = @"((0[1-9]|[1][012])[/](0[1-9]|[12][0-9]|3[01])[/](1(2[3-9][8-9]|[3-8][0-9][0-9]|9[0-6][0-9]|97[0-7]|24[0-7]))\s([0-1]\d|2[0-3])(:[0-5]\d))";
  158. //        //Ниже помесячно
  159. //        //string pattern = @"((((0[13578]|[1][02])[/](0[1-9]|[12][0-9]|3[01])[/](1(2[3-9][8-9]|[3-8][0-9][0-9]|9[0-6][0-9]|97[0-7])))|((0[469]|11)[/](0[1-9]|[12][0-9]|30)[/](1(2[3-9][8-9]|[3-8][0-9][0-9]|9[0-6][0-9]|97[0-7]|23[89]|24[0-7])))|((02)[/](0[1-9]|[12][0-9])[/](1(24[048]|25[26]|26[048]|27[26]|28[048]|29[26])|([3-8](0[048]|1[26]|2[048]|3[26]|4[048]|5[26]|6[048]|7[26]|8[048]|9[26]))|(9(0[048]|1[26]|2[048]|3[26]|4[048]|5[26]|6[048]|7[26]))))|((02)[/](0[1-9]|[12][0-8])[/](1(2(3[89]|4[1235679]|5[13457890]|6[1235679]|7[13457890]|8[1235679]|9[13457890]))|([3-8](0[1235679]|1[13457890]|2[1235679]|3[13457890]|4[1235679]|5[13457890]|6[1235679]|7[13457890]|8[1235679]|9[13457890]))|(9(0[1235679]|1[13457890]|2[1235679]|3[13457890]|4[1235679]|5[13457890]|6[1235679]|7[13457890]))))|((0[578]|[1][02])[/](0[1-9]|[12][0-9]|3[01])[/](1237))|((0[469]|11)[/](0[1-9]|[12][0-9]|30)[/](1237))|((03)[/](0[7-9]|[12][0-9]|3[01])[/](1237))|((01)[/](0[1-9]|[12][0-9]|3[01])[/](1978))|((02)[/](0[1-9]|1[0-9]|2[0-6])[/](1978)))\s([0-1]\d|2[0-3])(:[0-5]\d))|((((02)[/](0[1-9]|[12][0-9])[/](1(24[048]|25[26]|26[048]|27[26]|28[048]|29[26])|([3-8](0[048]|1[26]|2[048]|3[26]|4[048]|5[26]|6[048]|7[26]|8[048]|9[26]))|(9(0[048]|1[26]|2[048]|3[26]|4[048]|5[26]|6[048]|7[26]))))|((02)[/](0[1-9]|[12][0-8])[/](1(2(3[89]|4[1235679]|5[13457890]|6[1235679]|7[13457890]|8[1235679]|9[13457890]))|([3-8](0[1235679]|1[13457890]|2[1235679]|3[13457890]|4[1235679]|5[13457890]|6[1235679]|7[13457890]|8[1235679]|9[13457890]))|(9(0[1235679]|1[13457890]|2[1235679]|3[13457890]|4[1235679]|5[13457890]|6[1235679]|7[13457890])))))\s([0-1]\d|2[0-3])(:[0-5]\d))";
  160. //        //string pattern = @"((((0[13578]|[1][02])[/](0[1-9]|[12][0-9]|3[01])[/](1(2[3-9][8-9]|[3-8][0-9][0-9]|9[0-6][0-9]|97[0-7])))|((0[469]|11)[/](0[1-9]|[12][0-9]|30)[/](1(2[3-9][8-9]|[3-8][0-9][0-9]|9[0-6][0-9]|97[0-7]|23[89]|24[0-7])))|((0[578]|[1][02])[/](0[1-9]|[12][0-9]|3[01])[/](1237))|((0[469]|11)[/](0[1-9]|[12][0-9]|30)[/](1237))|((03)[/](0[7-9]|[12][0-9]|3[01])[/](1237))|((01)[/](0[1-9]|[12][0-9]|3[01])[/](1978))|((02)[/](0[1-9]|1[0-9]|2[0-6])[/](1978)))\s([0-1]\d|2[0-3])(:[0-5]\d))|((((02)[/](0[1-9]|[12][0-9])[/](1(24[048]|25[26]|26[048]|27[26]|28[048]|29[26])|([3-8](0[048]|1[26]|2[048]|3[26]|4[048]|5[26]|6[048]|7[26]|8[048]|9[26]))|(9(0[048]|1[26]|2[048]|3[26]|4[048]|5[26]|6[048]|7[26]))))|((02)[/](0[1-9]|[12][0-8])[/](1(2(3[89]|4[1235679]|5[13457890]|6[1235679]|7[13457890]|8[1235679]|9[13457890]))|([3-8](0[1235679]|1[13457890]|2[1235679]|3[13457890]|4[1235679]|5[13457890]|6[1235679]|7[13457890]|8[1235679]|9[13457890]))|(9(0[1235679]|1[13457890]|2[1235679]|3[13457890]|4[1235679]|5[13457890]|6[1235679]|7[13457890])))))\s([0-1]\d|2[0-3])(:[0-5]\d))";
  161. //        string pattern = @"(((((0[13578]|[1][02])[/](0[1-9]|[12][0-9]|3[01])[/](1(2[3-9][8-9]|[3-8][0-9][0-9]|9[0-6][0-9]|97[0-7])))|((0[469]|11)[/](0[1-9]|[12][0-9]|30)[/](1(2[3-9][8-9]|[3-8][0-9][0-9]|9[0-6][0-9]|97[0-7]|23[89]|24[0-7])))|((0[578]|[1][02])[/](0[1-9]|[12][0-9]|3[01])[/](1237))|((0[469]|11)[/](0[1-9]|[12][0-9]|30)[/](1237))|((03)[/](0[7-9]|[12][0-9]|3[01])[/](1237))|((01)[/](0[1-9]|[12][0-9]|3[01])[/](1978))|((02)[/](0[1-9]|1[0-9]|2[0-6])[/](1978)))\s([0-1]\d|2[0-3])(:[0-5]\d))|(((02)[/](0[1-9]|1[0-9]|2[0-8])[/](((1[3-8])[0-9]{2})|(19[0-6][0-9])|(197[0-7])))|((02)[/]29[/](((1[3-8])(04|08|[2468][048]|[13579][26]))|((19)(04|08|[246][048]|[1357][26])))))\s([0-1]\d|2[0-3])(:[0-5]\d))|(((03)[/](06)[/](1237))\s(1[2-9]|2[0-3])(:[0-5]\d))|(((02)[/](27)[/](1978))\s([0-1]\d|20)(:[0-5]\d))|(((02)[/](27)[/](1978))\s(21)((:[0-2]\d)|:3[0-5]))";
  162.  
  163. //        string[] names = { "01/03/1900 23:46", "12/23/1238 12:08", "01/32/1000", "03/06/1237 12:00", "02/27/1978 21:35", "04/30/1240 22:40", "03/07/1237 12:34", "01/12/1978 18:58", "02/29/1972 12:45", "02/29/1560 12:45", "02/28/1990 12:45", "02/27/1978 21:34", "03/06/1237 12:00" };
  164.  
  165. //        foreach (string name in names)
  166. //            Console.WriteLine(Regex.Match(name, pattern));
  167. //    }
  168. //}
  169. public class Ex8
  170. {
  171.     public static void Main()
  172.     {
  173.         Regex emailRegex = new Regex(@"^[\d,\w,\.]*@\w*.(com)?(ru)?$");
  174.         Regex passwordRegex = new Regex(@"^[a-z,A-Z,\d]*[a-z]+[a-z,A-Z,\d]*[A-Z]+[a-z,A-Z,\d]*\d+[a-z,A-Z,\d]*\.+[a-z,A-Z,\d]*$");
  175.         Regex numberOfPhone = new Regex(@"^[\+,1-9](?(?<=\+)([1-9]\(?(?(?<=\()(\d{3}\)\d{3}\-?\d{2}\-?\d{2}$)|(\d{3}\-?\d{3}\-?\d{2}\-?\d{2}$)))|(\(?(?(?<=\()(\d{3}\)\d{3}\-?\d{2}\-?\d{2}$)|(\d{3}\-?\d{3}\-?\d{2}\-?\d{2}$))))");
  176.         Regex date = new Regex(@"^((0?[1-9])|(1[0-2]))[/]((0[1-9])|([12]\d)|3[0-1])[/]\d{0,4}$");
  177.  
  178.         Console.WriteLine("Enter a password");
  179.         String password = Console.ReadLine();
  180.         Console.WriteLine($"Accept:{passwordRegex.IsMatch(password)}");
  181.  
  182.         Console.WriteLine("Enter an e-mail");
  183.         String email = Console.ReadLine();
  184.         Console.WriteLine($"Accept:{emailRegex.IsMatch(email)}");
  185.  
  186.         Console.WriteLine("Enter a phone");
  187.         String phone = Console.ReadLine();
  188.         Console.WriteLine($"Accept:{numberOfPhone.IsMatch(phone)}");
  189.  
  190.         Console.WriteLine("Enter a date");
  191.         String date_ = Console.ReadLine();
  192.         Console.WriteLine($"Accept:{date.IsMatch(date_)}");
  193.  
  194.     }
  195. }
  196.  
  197.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement