一个正则问题!!!
时间:2011-12-20
来源:互联网
C# code
public static void GetA7() { string str = "windows 97,windows 98,windows xp,windows server 2003,windows 7,windows server 2008,linux,niunix"; Regex regex = new Regex(@"(?<!windows)[^,]+"); Console.WriteLine("哪些不是windows系统:"); foreach (Match match in regex.Matches(str)) { Console.WriteLine(match); } }
C# code
public static void GetA9() { string str = "长沙是湖南的,岳阳是湖南的,湘潭是湖南的,株洲是湖南的,郴州是湖南的,武汉是湖北的,深圳是广东的"; //Regex regex = new Regex(@"[\u4e00-\u9fa5]+(?!是湖南的)"); Regex regex = new Regex(@"[^,]+(?!是湖南的)"); Console.WriteLine("下面不是湖南的城市:"); foreach (Match match in regex.Matches(str)) { Console.WriteLine(match); } }
肯定的(?<=)和(?=)都可以通过!!
否定的不知道为什么出了问题!!!
作者: chaichangaini 发布时间: 2011-12-20
作者: chaichangaini 发布时间: 2011-12-20
作者: chaichangaini 发布时间: 2011-12-20
作者: jianghui7897 发布时间: 2011-12-20
其实我认为楼主就是正则高手。。。
晕 在学习!
也是菜鸟啊!
作者: chaichangaini 发布时间: 2011-12-20
作者: chaichangaini 发布时间: 2011-12-20
void Main() { string str = "windows 97,windows 98,windows xp,windows server 2003,windows 7,windows server 2008,linux,niunix"; Regex regex = new Regex(@"^(?!windows).+$"); Console.WriteLine("哪些不是windows系统:"); foreach (var s in str.Split(',')) { if(regex.IsMatch(s)) Console.WriteLine(regex.Match(s).Value); } } void Main() { string str = "长沙是湖南的,岳阳是湖南的,湘潭是湖南的,株洲是湖南的,郴州是湖南的,武汉是湖北的,深圳是广东的"; Regex regex = new Regex(@"^.+(?<!是湖南的)$"); Console.WriteLine("下面不是湖南的城市:"); foreach (var s in str.Split(',')) { if(regex.IsMatch(s)) Console.WriteLine(regex.Match(s).Value); } }
资料参考: http://blog.csdn.net/lxcnn/article/details/4304754
http://blog.csdn.net/lxcnn/article/details/4954134
作者: q107770540 发布时间: 2011-12-20
C# code
void Main()
{
string str = "windows 97,windows 98,windows xp,windows server 2003,windows 7,windows server 2008,linux,niunix";
Regex regex = new Regex(@"^(?!windows).+$");
……
问下这种(?!) (?<!)只匹配^$这种完全满足的情况吗?
作者: chaichangaini 发布时间: 2011-12-20
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28