Esempio n. 1
0
        public static void Main(string[] args)
        {
            WorkWithRegexInConsole openTagInRegex = new WorkWithRegexInConsole(2, openTag);
            string inputString = openTagInRegex.InputString;
            WorkWithRegexInConsole closeTagInRegex = new WorkWithRegexInConsole(2, closeTag, false);

            closeTagInRegex.InputString = inputString;
            MatchCollection openTagMatches  = openTagInRegex.GetAllMatches();
            MatchCollection closeTagMatches = closeTagInRegex.GetAllMatches();
            string          result          = inputString;

            foreach (var item in openTagMatches)
            {
                int startIndex = result.IndexOf(item.ToString());
                result = result.Remove(startIndex, item.ToString().Length).Insert(startIndex, changeOn);
            }

            foreach (var item in closeTagMatches)
            {
                int startIndex = result.IndexOf(item.ToString());
                result = result.Remove(startIndex, item.ToString().Length).Insert(startIndex, changeOn);
            }

            Console.WriteLine();
            Console.WriteLine("Input string: ");
            Console.WriteLine(inputString);
            Console.WriteLine("Changed input string: ");
            Console.WriteLine(result);

            result          = openTagInRegex.ExampleString;
            openTagMatches  = openTagInRegex.GetAllMatchesInExample();
            closeTagMatches = closeTagInRegex.GetAllMatchesInExample();
            foreach (var item in openTagMatches)
            {
                int startIndex = result.IndexOf(item.ToString());
                result = result.Remove(startIndex, item.ToString().Length).Insert(startIndex, changeOn);
            }

            foreach (var item in closeTagMatches)
            {
                int startIndex = result.IndexOf(item.ToString());
                result = result.Remove(startIndex, item.ToString().Length).Insert(startIndex, changeOn);
            }

            Console.WriteLine();
            Console.WriteLine("Example string: ");
            Console.WriteLine(closeTagInRegex.ExampleString);
            Console.WriteLine("Changed example string: ");
            Console.WriteLine(result);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            WorkWithRegexInConsole workWithEmailRegex = new WorkWithRegexInConsole(3, reg);
            MatchCollection        matches            = workWithEmailRegex.GetAllMatches();

            Console.WriteLine("Found email addresses:");
            foreach (var item in matches)
            {
                Console.WriteLine(item.ToString());
            }

            Console.WriteLine();
            Console.WriteLine($"For example:{Environment.NewLine}{workWithEmailRegex.ExampleString}{Environment.NewLine}Found email addresses:");
            matches = workWithEmailRegex.GetAllMatchesInExample();
            foreach (var item in matches)
            {
                Console.WriteLine(item.ToString());
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            WorkWithRegexInConsole workWithRegex = new WorkWithRegexInConsole(1, reg);
            MatchCollection        matches       = workWithRegex.GetAllMatches();
            string find = "no ";

            if (matches.Count > 0)
            {
                foreach (var item in matches)
                {
                    if (DateTime.TryParse(item.ToString(), out DateTime notUsedDate))
                    {
                        find = string.Empty;
                        break;
                    }
                }
            }

            Console.WriteLine($"Input string \"{workWithRegex.InputString}\" has {find}date.");

            find    = "no ";
            matches = workWithRegex.GetAllMatchesInExample();
            if (matches.Count > 0)
            {
                foreach (var item in matches)
                {
                    if (DateTime.TryParse(item.ToString(), out DateTime notUsedDate))
                    {
                        find = string.Empty;
                        break;
                    }
                }
            }

            Console.WriteLine($"Example string \"{workWithRegex.ExampleString}\" has {find}date.");
        }