C# 中正则表达式

其实正则表达式都差不多,这里只是简单做个记录,防止忘记

例子:

static void Main(string[] args)
        {
            string str = "j5sjf333jw";
            string reg = @"^[\dA-Za-z]*$";
            Match match = Regex.Match(str,reg);
            if (match.Success)
            {
                Console.WriteLine("输入正确!");
            }
            else
            {
                Console.WriteLine("输入有误!");
            }
            //Regex reg = new Regex(@"^[0 - 9] * $");
            //string modified = reg.Replace(str, "NAME=WANG;");

            //Console.WriteLine(modified);


            //Match match = reg.Match(str);
            //string value = match.Groups[1].Value;
            //Console.WriteLine("value的值为:{0}", value);
            Console.ReadKey();
        }

 

posted on 2018-06-12 16:21  尘世辣么美  阅读(96)  评论(0编辑  收藏  举报

导航