日期:2014-05-18 浏览次数:21043 次
Regex re = new Regex(@"[\\/""\[\]\:\\|\<\>\+\=\;\,\?\*\@]", RegexOptions.None);
             
if(re.IsMatch("你要验证的字符串"))
{
     //含用特殊字符
}
else
{
    //不含用特殊字符
}
------解决方案--------------------
原来是要排除,用下面这个
  static void Main(string[] args)
            {
                string str = @"\/ "" [ ] : | cb< > + = ; , ? * @abc";
                StringBuilder sb = new StringBuilder();
                Regex re = new Regex(@"[^\\/""""\[\]\:\\|\<\>\+\=\;\,\?\*\@]", RegexOptions.IgnorePatternWhitespace);
                MatchCollection mc = re.Matches(str);
                foreach (Match ma in mc)
                {
                    sb.Append(ma.Value.Trim());
                }
                Console.WriteLine(sb);
                Console.ReadLine();                                
            }
//输出结果:cbabc