正则表达式匹配 非XXX的行




1111111111111
前边有内容,不定123.123.123.10后边有内容,不定
3333333333333
4444444444444


如何匹配"非:.+123.123.123.10.+ "


匹配结果是,
1111111111111

3333333333333
4444444444444

结论:

^(?!.*123.123.123.10).*$
或C#里这么操作:

textBox2.Text = Regex.Replace(textBox1.Text, @"\n.*123\.123\.123\.10.*\n", "\n\r\n");
string result = Regex.Replace(str, @"^.*?123\.123\.123\.10.*$", "", RegexOptions.Multiline);
Regex reg =new Regex(@"(?<=^|\r\n)(?!123\.123\.123\.10).+");

总结:

匹配非“非内容”的行的表达式应该写成:^(?!.*非内容).*$


===================================
另,再来个例子:
2008-07-14 15:44:40 W3SVC491 60.27.236.4 GET /Item/How-To-Connection-My-Computer-Flow-IP-yongfa365.html - 80 - 74.6.22.106 Mozilla/5.0+(compatible;+Yahoo!+Slurp;+http://help.yahoo.com/help/us/ysearch/slurp) 200 0 0
2008-07-14 15:44:51 W3SVC491 60.27.236.4 GET /item/Clear.bat-System-Windows-98-XP-2003-yongfa365.html - 80 - 124.73.140.102 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0) 200 0 64
2008-07-14 15:44:51 W3SVC491 60.27.236.4 GET /item/Clear.bat-System-Windows-98-XP-2003-yongfa365.html - 80 - 124.73.140.102 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0) 206 0 64
2008-07-14 15:47:11 W3SVC491 60.27.236.4 GET /Articles.xml - 80 - 65.214.44.28 Bloglines/3.1+(http://www.bloglines.com;+1+subscriber) 200 0 64
2008-07-14 15:47:47 W3SVC491 60.27.236.4 GET /Item/SQL-Server-Store-More-Than-8000-WRITETEXT-UPDATETEXT-yongfa365.html - 80 - 59.125.118.13 Trend+Micro+Web+Protection+Add-On+1.10.1144 200 0 0

找出上而面的行里的,不是以“200 0 64”结尾的行,然后删除

^(?!.*200 0 64).*$

而我一直是这么测试的:
^(?!.*200 0 64)$
没有后边的.* 因为我觉得后边已经没有内容了,所以没写 .* 而不写就不对,写了才行,哪位高人可以再指点下。

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3