正则表达式替换字符串

时间:2023-01-03 12:35:22

正则表达式替换字符串

string pattern = @"CREATE\s+PROC(EDURE)?";
            Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);

            string inputStr = "CREATe  PROC spTest";

            // Replace runs of white space in the input string with a
            // comma and a blank.
            string outputStr = rgx.Replace(inputStr, "ALTER PROCEDURE");

            // Display the resulting string.
            Console.WriteLine("Pattern:       \"{0}\"", pattern);
            Console.WriteLine("Input string:  \"{0}\"", inputStr);
            Console.WriteLine("Output string: \"{0}\"", outputStr);