比如以下的代码就是用来测试用正则表达式匹配从 0xff 到 0xffff 的字符。而值范围在 0 到 0xfe 的所有字符是不能被匹配的。
以下为引用的内容:
复制代码 代码如下:
Regex 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 好啊,呵呵!
以下为引用的内容:
复制代码 代码如下:
var 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 + '!' );
}
}
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 纯音入心系列纯音乐《中央民族乐团-古筝传奇》1CD[MP3][253.1MB]
- 江玲.1989-这样你才爱我,是吗?【新作有声】【WAV+CUE】
- 郭美美.2010-我是郭美美【华纳】【WAV+CUE】
- 黄心懋1991-轻忧郁【滚石】【WAV+CUE】
- 群星.2000-大地金曲世纪回顾2CD【大地】【WAV+CUE】
- 王菲.1996-浮躁(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 群星.2022-传家电视剧原声带【东阳欢娱】【FLAC分轨】
- 《摇滚教父 伍佰黄金精选 2CD》 [WAV+CUE][1GB]
- 《凤凰传奇 我从草原来》[WAV/分轨][400MB]
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]