高分求一正则表达式要求:有一字符串“xx description xxx....”,求验证该字符串中不包括“description”的正则表达式满足即给分,多谢!

解决方案 »

  1.   

    你判断个包括,然后else一下不就好了?
      

  2.   

    是啊,if(str.contains("description"))
      

  3.   

    var regex =/^(?!description $)/;
    alert(regex.test("description "));\b((?!description )\w)+\b 
    [^?!description ]+ 
    或contains
      

  4.   

    Regex re = new Regex(@"^((?!description).)*$");
    bool yesorno = re.IsMatch("your string");
      

  5.   


    首先感谢,但是经测试没有通过,第一种无论有无"description"都返回false,第二种则相反,全部返回true,不知道您测试过没有?
      

  6.   


    我用您的方法试了一次,还是不行,我把字符串完整贴出来,请大家帮忙看看string strERX = @"aa2009-09-25 11:04:34
    M  1 COMPLD
    EN=0   ENDESC=执行成功
    UserType=VLAN,AdminStatus=1,OutVlan=2561,VlanID=256,LoopBack=5,InputPolicy=pro3M,OuputPolicy=pro3M,Profile=,IP=125.70.231.9
    ----------------------------------------
    <SAVE=1,ENDFLAG=#,TIMEOUT=120><COMMAND=<10>show configuration interface gigabitEthernet 12/0.125610256 | begin 12/0.125610256/>*/
     12/0.125610256

     svlan id 2561 256
     svlan ethertype 8100
     ip description 79942234/3M/20090925/tongbu/g/12/0.256
     ip unnumbered loopback 5
     ip policy input pro3M
     ip policy output pro3M
    BAS-EY2F-ERX1440-2#
    <SAVE=1,ENDFLAG=#,TIMEOUT=300/><COMMAND=<10>sh conf ca ip | inc Ethernet12/0.125610256/>*/
    sh conf ca ip | inc Ethernet12/0.125610256
    ip route 125.70.231.9 255.255.255.255 GigabitEthernet12/0.125610256BAS-EY2F-ERX1440-2#----------------------------------------
    ;";
      

  7.   

    ip description 79942234/3M/20090925/tongbu/g/12/0.256就是要匹配这行没有description
      

  8.   

    <SCRIPT LANGUAGE="JavaScript">
    var re = new RegExp("^((?!description).)*$", "");
    var str1 = re.test("xx description xxx....");
    var str2 = re.test("aaaaaaaaaaaaaaa");
    alert(str1);
    alert(str2);
    </SCRIPT>第一个false
    第二个true
      

  9.   


    string input;
    bool b = Regex.Ismatch(input, "(?si)^(?!.*description)");//input = "xx description xxx...."; b=false
    ////input = "xx adescription xxx...."; b=true
      

  10.   

    <SCRIPT LANGUAGE="JavaScript">
    var re = new RegExp("^((?!description).)*$", "");
    var str1 = re.test("ip description 79942234/3M/20090925/tongbu/g/12/0.256 ");
    alert(str1);
    </SCRIPT>返回false,证明存在
      

  11.   

    要验证整个字符串不包含,还是每一行是否包含?
                string strERX = @"aa2009-09-25 11:04:34 
    M  1 COMPLD 
    EN=0  ENDESC=执行成功 
    UserType=VLAN,AdminStatus=1,OutVlan=2561,VlanID=256,LoopBack=5,InputPolicy=pro3M,OuputPolicy=pro3M,Profile=,IP=125.70.231.9 
    ---------------------------------------- 
    <SAVE=1,ENDFLAG=#,TIMEOUT=120> <COMMAND= <10>show configuration interface gigabitEthernet 12/0.125610256 | begin 12/0.125610256/>*/ 
    12/0.125610256 

    svlan id 2561 256 
    svlan ethertype 8100 
    ip description 79942234/3M/20090925/tongbu/g/12/0.256 
    ip unnumbered loopback 5 
    ip policy input pro3M 
    ip policy output pro3M 
    BAS-EY2F-ERX1440-2# 
    <SAVE=1,ENDFLAG=#,TIMEOUT=300/> <COMMAND= <10>sh conf ca ip | inc Ethernet12/0.125610256/>*/ 
    sh conf ca ip | inc Ethernet12/0.125610256 
    ip route 125.70.231.9 255.255.255.255 GigabitEthernet12/0.125610256 BAS-EY2F-ERX1440-2# ---------------------------------------- 
    ;";
                Regex reg = new Regex(@"(?is)^(?>(?:(?!description).)*)$");
                if (reg.IsMatch(strERX))
                {
                    richTextBox2.Text = "不包含!";
                }
                else
                {
                    richTextBox2.Text = "包含!";
                }
                /*--------输出------------
                包含!
                */
      

  12.   


    感谢您的回帖,不过用这个表达式,我这里还是没有通过,现贴出代码供参考string strERX = @"2009-09-25 11:04:34
                    M  1 COMPLD
                    EN=0   ENDESC=执行成功
                    UserType=VLAN,AdminStatus=1,OutVlan=2561,VlanID=256,LoopBack=5,InputPolicy=pro3M,OuputPolicy=pro3M,Profile=,IP=125.70.231.9
                    ----------------------------------------
                    <SAVE=1,ENDFLAG=#,TIMEOUT=120><COMMAND=<10>show configuration interface gigabitEthernet 12/0.125610256 | begin 12/0.125610256/>*/
                     12/0.125610256
                    ! 
                     svlan id 2561 256
                     svlan ethertype 8100
                     ip description 79942234/3M/20090925/tongbu/g/12/0.256
                     ip unnumbered loopback 5
                     ip policy input pro3M
                     ip policy output pro3M
                    BAS-EY2F-ERX1440-2#
                    <SAVE=1,ENDFLAG=#,TIMEOUT=300/><COMMAND=<10>sh conf ca ip | inc Ethernet12/0.125610256/>*/
                    sh conf ca ip | inc Ethernet12/0.125610256
                    ip route 125.70.231.9 255.255.255.255 GigabitEthernet12/0.125610256                BAS-EY2F-ERX1440-2#                ----------------------------------------
                    ;";
                string strRexExpress = @"(?si)^(?!.*description)";            Regex reg = new Regex(strRexExpress, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);            if (reg.IsMatch(strERX))
                {
                    MessageBox.Show("match!");
                }
    无论是否存在description,都返回true
      

  13.   

    按道理说楼主的需求应该不仅仅是验证是否包含description这一单词这么简单,否完完全没必要用正则表达式
      

  14.   


    var regex =/^.*description.*$/; 
    alert(!regex.test("sfdsf description sdfds")); 你正则表达是匹配,然后程序再非判断
      

  15.   


    你的正则跟lxcnn给的不一样楼主仔细看啊,我测试lxcnn的是可以的