我指的是如何写正则表达式,不是如何把单引号去掉

解决方案 »

  1.   

    string str = 要验证的字符串;
    Regex re = new Regex("[']"); 
    if (re.IsMatch(str))
    {
       不能含有单引号;
    }
    else
    {
       ok;
    }
    下面是我用的一个函数
            // ============  检查字符串  =============
            // Str为要检查字符,Strpattern为匹配的正则表达式   返回值: true|false  
            public bool ChkRegex(string Str,string Strpattern)
            {
                Regex re = new Regex(Strpattern); 
                return re.IsMatch(Str);
            }