请教一个正则表达式问题:
23452abc234534
34534cdf345333
45995sdf988997
28238sfh902093
如上面我要匹配不带有cdf或sdf的字串,怎样做?

解决方案 »

  1.   

    you should just check withstring s = "...";if (s.IndexOf("cdf") == -1 && s.IndexOf("sdf") == -1)
    {
     //
    }
      

  2.   

    这种情况没必要用正则表达式吧,个数不多的情况用IndexOf方便些。如果非得要用有正则:
    if Regex.IsMatch( xxx , @"^(?>(cdf|sdf)(?<d>)|.?)*(?(d)(?!))$" /* RegexOptions.IgnoreCase */" )
    {
       Valid string
    }
      

  3.   

    string strReg=@"(^(?!.*?sdf|.*?cdf).*$)";
    MatchCollection _mc=Regex.Matches(YOURTEXT,strReg,RegexOptions.IgnoreCase);
    foreach(Match _current in _mc)
    {
      string strValue=_current.Value;
    }这样行不行?