高分求一正则表达式要求:有一字符串“xx description xxx....”,求验证该字符串中不包括“description”的正则表达式满足即给分,多谢!
解决方案 »
- 在visual studio命令行中 用csc来编译c#的.cs文件生成exe文件的路径设置
- tabcontrol中的tabpage如何用鼠标拖动达到tabpage的顺序发生改变
- 遍历多维数组
- ■■■■■■■■■■■■问一个技术问题和一个不是技术问题的问题■■■■■■■■■■■■济南-烟台
- C#Type类字段问题 急 急 急 !!!分不多 但请帮帮忙
- 用C#做CS程序跟DELPHI比较有什么优缺点啊,我该选择谁啊哪种呢??
- 在web中如何编辑word文档?
- 线程委托的问题
- 请大家看看这篇CSDN上这篇文章,讲COM+的, 可我觉得就是COM。。。
- 请问下大家都用的什么编程框架?
- C#硬件控制问题
- 简单的问题,求教!
alert(regex.test("description "));\b((?!description )\w)+\b
[^?!description ]+
或contains
bool yesorno = re.IsMatch("your string");
首先感谢,但是经测试没有通过,第一种无论有无"description"都返回false,第二种则相反,全部返回true,不知道您测试过没有?
我用您的方法试了一次,还是不行,我把字符串完整贴出来,请大家帮忙看看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#----------------------------------------
;";
var re = new RegExp("^((?!description).)*$", "");
var str1 = re.test("xx description xxx....");
var str2 = re.test("aaaaaaaaaaaaaaa");
alert(str1);
alert(str2);
</SCRIPT>第一个false
第二个true
string input;
bool b = Regex.Ismatch(input, "(?si)^(?!.*description)");//input = "xx description xxx...."; b=false
////input = "xx adescription xxx...."; b=true
var re = new RegExp("^((?!description).)*$", "");
var str1 = re.test("ip description 79942234/3M/20090925/tongbu/g/12/0.256 ");
alert(str1);
</SCRIPT>返回false,证明存在
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 = "包含!";
}
/*--------输出------------
包含!
*/
感谢您的回帖,不过用这个表达式,我这里还是没有通过,现贴出代码供参考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
var regex =/^.*description.*$/;
alert(!regex.test("sfdsf description sdfds")); 你正则表达是匹配,然后程序再非判断
你的正则跟lxcnn给的不一样楼主仔细看啊,我测试lxcnn的是可以的