All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
收集ASP转ASP.NET过程典型问题_[Asp.Net教程]
ASP.NET技巧:一些常用的数据操作类_[Asp.Net教程]
利用C#创建,IIS,站点并设置.NET,Framework版本为ASP.NET,2.0,的方法,二_[Asp.Net教程]
C#教程:DLL动态链接库的DLL依赖项
浅谈SQL,Server,2008中的行压缩_mssql学习_编程技术
php+mysql实现无限级分类_[PHP教程]
asp.net2.0网站语法之HTML服务器控件语法
新手入门:PHP网站开发中常见问题汇总_php资料_编程技术
如何在十天内学会php之第八天_[PHP教程]
怎样才能成为PHP高手学会懒惰的编程_[PHP教程]
Reading number is top 10 pictures
30 beautiful school beauty2
我国房地产真相
Black and white also sexy--YanLiu2
Lewd,it is too lewd.
Forced sex girl living abroad1
美女就是美女
NeedWallpaper10
29 the belle stars after bath figure4
yy365网站上的美女2
The real super beauty8
Download software ranking
Unix video tutorial13
Tram sex maniac 2 (H) rar bag16
Macromedia Dreamweaver 8
Unix video tutorial14
linux高级编程
C#程序员参考手册
Red cliff
Unix video tutorial8
Eclipse-CALMSANNY (second edition)
White deer villiage
aaa published in(发表于) 2013/12/18 7:52:02 Edit(编辑)
.NET开发,正则表达式中的,Bug_.net资料_编程技术

.NET开发,正则表达式中的,Bug_.net资料_编程技术

.NET开发 正则表达式中的 Bug_.net资料_编程技术-你的首页-uuhomepage.com

  又发现了一个 .net 的 bug!最近在使用正则表达式的时候发现:在忽略大小写的时候,匹配值从 0xff 到 0xffff 之间的所有字符,正则表达式竟然也能匹配两个 ASCII 字符:i(code: 0x69) 和 I(code: 0x49);但是仍然不能匹配其他的 ASCII 字母和数字。


  比如以下的代码就是用来测试用正则表达式匹配从 0xff 到 0xffff 的字符。而值范围在 0 到 0xfe 的所有字符是不能被匹配的。


  1234567891011121314151617Regex regex = new Regex(@"[\u00FF-\uFFFF]+");
  // The characters, whoes value are smaller than 0xff, are not expected to be matched.
  for (int i = 0; i < 0xff; i++) {
  string s = new string(new char[] { (char)i });
  Debug.Assert(
  !regex.IsMatch(s),
  string.Format("The character was not expected to be matched: 0x{0:X}!", i));
  }
  // However, the characters whoes value are greater than 0xfe are expected to be matched.
  for (int i = 0xff; i <= 0xffff; i++) {
  string s = new string(new char[] { (char)i });
  Debug.Assert(
  regex.IsMatch(s),
  string.Format("The character was expected to be matched: 0x{0:X}!", i));
  }


  这时的运行结果是正常的,没有任何的断言错误出现。


  然而当使用忽略大小写的匹配模式时,结果就不一样了。将上面代码中的第一行改成:


  1Regex regex = new Regex(@"[\u00FF-\uFFFF]+", RegexOptions.IgnoreCase);


  程序运行的时候就会有两处断言错误。它们分别是字符值为 73 和 105,也就是小写字母 i 和大写字母 I。 这个 bug 非常奇怪,别的字符都很正常!而且用 javascript 脚本在 IE (版本是6.0)里面运行也同样有这么 bug 存在(比如下面这段代码)。然而在 Firefox 中运行就是没有问题的。还是 Firefox 好啊,呵呵!


  1234567891011121314151617var re = /[\u00FF-\uFFFF]+/;
  // var re = /[\u00FF-\uFFFF]+/i;
  for(var i=0; i<0xff; i++) {
  var s = String.fromCharCode( i );
  if ( re.test(s) ){
  alert( 'Should not be matched: ' + i + '!' );
  }
  }
  for(var i=0xff; i<=0xffff; i++) {
  var s = String.fromCharCode( i );
  if ( !re.test(s) ){
  alert( 'Should be matched: ' + i + '!' );
  }
  }





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.