C#中运用正则表达式获取字符串

来源:互联网 发布:mac系统能玩lol吗 编辑:程序博客网 时间:2024/06/05 05:01
  1. public void zhengze()  
  2. {  
  3.     //要匹配的字符串  
  4.     string text = "1A 2B 3C 4D 5E 6F 7G 8H 9I 10J 11Q 12J 13K 14L 15M 16N ffee80 #800080";  
  5.     //正则表达式  
  6.     string pattern = "[\s\n]*"2B"(?<name>2B)\s*";  
  7.     //使用RegexOptions.IgnoreCase枚举值表示不区分大小写  
  8.     Regex r = new Regex(pattern, RegexOptions.IgnoreCase);  
  9.     //使用正则表达式匹配字符串,仅返回一次匹配结果  
  10.     Match m = r.Match(text);  
  11.     while (m.Success)  
  12.     { 
  13. response.write(name);
  14.     }  
  15. }  
今天学习的新知识,好像写法有点错,稍后修改。
0 0
原创粉丝点击