日期:2014-05-17  浏览次数:20803 次

为什么这个正则表达式会出错呢?
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace homework1._3
{
    class Program
    {
        static void isvalidzipcode(ref int a, out string b,out string c)
        {
            a = 11111;
            b ="-CCCC";
            c = a + b;
        }
        static void Main(string[] args)
        {
            int val=0;
            string str1, str2;
            Boolean judge;
            judge="^\d{5}-([a-zA-Z]){4}$";
            isvalidzipcode(ref val, out str1,out str2);
            Console.WriteLine("{0}", str2);
            Console.WriteLine(judge);
            Console.ReadLine();
        }
    }
}


这个程序是判断c是否属于11111-CCCC格式,即前五位数字,第六位横杠,后四位字母。
输出是先输出1111-CCCC,然后再输入判断结果。
我在网上查到了这个正则表达式,没什么问题,但为什么把它加入到程序中就不对了呢?
VS表示就这一行有问题。
应该怎么修改?

------解决方案--------------------
只是写了个表达式,怎么匹配了,没见你用正则啊,你直接输出了 judge
C# code

            Regex reg = new Regex(@"^\d{5}-([a-zA-Z]){4}$");
            Match mm = reg.Match(str2);