示例#1
0
        private static int FindMatches(string reg, string workString)
        {
            WorkWithRegexInConsole workWithRegex = new WorkWithRegexInConsole(5, reg, false);

            workWithRegex.InputString = workString;
            MatchCollection matches = workWithRegex.GetAllMatches();

            return(matches.Count);
        }
示例#2
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);
        }
示例#3
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());
            }
        }
示例#4
0
        public static void Main(string[] args)
        {
            WorkWithRegexInConsole findNumberInRegex = new WorkWithRegexInConsole(4, regForNumber);

            if (findNumberInRegex.GetAllMatches().Count > 0)
            {
                Console.WriteLine("Input string is a number in ordinary notation");
                return;
            }

            WorkWithRegexInConsole findENumberInRegex = new WorkWithRegexInConsole(4, regForENumber, false);

            findENumberInRegex.InputString = findNumberInRegex.InputString;
            if (findENumberInRegex.GetAllMatches().Count > 0)
            {
                Console.WriteLine("Input string is a number in scientific notation");
                return;
            }

            Console.WriteLine("Input string is not a number.");
        }
示例#5
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.");
        }