以下为引用的内容:
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);
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 + '!' );
}
}