Advertisement
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.Threading.Tasks;
- using System.Text.RegularExpressions;
- //public class Ex1
- //{
- // public static void Main()
- // {
- // int count = 0;
- // //string pattern = @"((^0)(?!\.)) (\((\d*[1-9]+\d*)\)) (^[\+-]?(0(?=\.)|[1-9]\d*) (\.((?(0+(?=[1-9]*))(?=[1-9]*))|([1-9]+)|([1-9]+)$)+(\((\d*[1-9]+\d*)\))?$)?
- // string pattern = @"((^[\+-]?(0(?=\.)|[1-9]\d*)(\.(((0+)(?=[1-9]+))|([1-9]+)|(0+)(?=\())+(\((\d*[1-9]+\d*)\))?)$)|((^0)(?!\.))|(^[\+-]?(^(0)$|[1-9]\d*$)))";
- // //string[] names = { "0.0(64)5", "-0.5", "0.5(1001010)", "3.75000001","0.0000000","2", "+0..56", "-0", "1000"};
- // 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" };
- // foreach (string name in names)
- // {
- // if (Regex.IsMatch(name, pattern))
- // {
- // Console.WriteLine(Regex.Match(name, pattern));
- // count++;
- // }
- // }
- // Console.WriteLine(count);
- // }
- //}
- //public class Ex2
- //{
- // public static void Main()
- // {
- // string pattern = "^(0+|1+|((01)+0?)|((10)+1?))$";
- // string[] names = { "11111", "10001", "10101", "00001","0000","01010011011" };
- // foreach (string name in names)
- // Console.WriteLine(Regex.Match(name, pattern));
- // }
- //}
- //public class Ex3
- //{
- // public static void Main()
- // {
- // Random x = new Random();
- // string pattern = @"^\d*[02468]$";
- // Regex rgx = new Regex(pattern);
- // int count = 0;
- // int count2 = 0;
- // while (count2 < 10)
- // {
- // int n = x.Next(1, 1000);
- // string s = n.ToString();
- // if (rgx.IsMatch(s))
- // {
- // count2++;
- // Console.Write(s + "\n");
- // }
- // count++;
- // }
- // Console.Write("count = " + count + "\n");
- // }
- //}
- //public class Ex4
- //{
- // public static void Main()
- // {
- // Random x = new Random();
- // string pattern = @"^[13579]*[02468]{0,2}[13579]*$";
- // Regex rgx = new Regex(pattern);
- // int count = 0;
- // int count2 = 0;
- // while (count2 < 10)
- // {
- // int n = x.Next(1, 1000000);
- // string s = n.ToString();
- // if (rgx.IsMatch(s))
- // {
- // count2++;
- // Console.Write(s + "\n");
- // }
- // count++;
- // }
- // Console.Write("count = " + count + "\n");
- // }
- //}
- //public class Ex5
- //{
- // public static void Main()
- // {
- // Random x = new Random();
- // string pattern = @"^[02468]{4,5}$";
- // Regex rgx = new Regex(pattern);
- // int count = 0;
- // int count2 = 0;
- // while (count2 < 10)
- // {
- // int n = x.Next(1, 1000000);
- // string s = n.ToString();
- // if (rgx.IsMatch(s))
- // {
- // count2++;
- // Console.Write(s + "\n");
- // }
- // count++;
- // }
- // Console.Write("count = " + count + "\n");
- // }
- //}
- //public class Ex6
- //{
- // public static void Main()
- // {
- // Random x = new Random();
- // string pattern = @"^\d*[02468]{2}\d*[02468]{2}\d*$";
- // Regex rgx = new Regex(pattern);
- // int count = 0;
- // int count2 = 0;
- // while (count2 < 10)
- // {
- // int n = x.Next(1, 1000000);
- // string s = n.ToString();
- // if (rgx.IsMatch(s))
- // {
- // count2++;
- // Console.Write(s + "\n");
- // }
- // count++;
- // }
- // Console.Write("count = " + count + "\n");
- // }
- //}
- //пароль[A - Za - z0 - 9_\.\!#\*\?\-\+,]{8,17}
- //email([\w\.\😏 +@[\w] + (\.com)| (\.ru)| (\.org))
- //телефон(((\+7) | 8 |)?[0 - 9]
- //{ 10})
- //public static void Main()
- //{
- // string pattern = @" ";
- // string[] names = { " " };
- // foreach (string name in names)
- // Console.WriteLine(Regex.Match(name, pattern));
- //}
- //public class Ex7
- //{
- // public static void Main()
- // {
- // //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]))))$";
- // //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))";
- // //Ниже помесячно
- // //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))";
- // //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))";
- // 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]))";
- // 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" };
- // foreach (string name in names)
- // Console.WriteLine(Regex.Match(name, pattern));
- // }
- //}
- public class Ex8
- {
- public static void Main()
- {
- Regex emailRegex = new Regex(@"^[\d,\w,\.]*@\w*.(com)?(ru)?$");
- 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]*$");
- 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}$))))");
- Regex date = new Regex(@"^((0?[1-9])|(1[0-2]))[/]((0[1-9])|([12]\d)|3[0-1])[/]\d{0,4}$");
- Console.WriteLine("Enter a password");
- String password = Console.ReadLine();
- Console.WriteLine($"Accept:{passwordRegex.IsMatch(password)}");
- Console.WriteLine("Enter an e-mail");
- String email = Console.ReadLine();
- Console.WriteLine($"Accept:{emailRegex.IsMatch(email)}");
- Console.WriteLine("Enter a phone");
- String phone = Console.ReadLine();
- Console.WriteLine($"Accept:{numberOfPhone.IsMatch(phone)}");
- Console.WriteLine("Enter a date");
- String date_ = Console.ReadLine();
- Console.WriteLine($"Accept:{date.IsMatch(date_)}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement