and a. NET bug! recently found in the use of regular expressions: When ignoring the case, match the values from 0xFF to 0xFFFF of all the characters, the regular expression can also match two ASCII characters: I (code:0x69) and I (code:0x49 ), but still cannot match other ASCII letters and numbers.
For example, the following code is used to test characters that match a regular expression from 0xFF to 0xFFFF. All characters with a value range of 0 to 0xFE cannot be matched.
1234567891011121314151617Regex regex = new Regex (@ "[\u00ff-\uffff]+");
The characters, whoes value are smaller than 0xFF, are not expected to is 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 is not expected to is 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 is expected to be matched:0x{0:x}!", i));
}
The results of this operation are normal and no assertion error occurs.
However, when you use a matching pattern that ignores case, the results are different. Change the first line in the above code to:
1Regex regex = new Regex (@ "[\u00ff-\uffff]+", regexoptions.ignorecase);
When the program runs, there are two assertion errors. They are character values 73 and 105, which are lowercase i and capital letter I. This bug is very strange, the other characters are very normal! and using JavaScript scripts to run in IE (version 6.0) also has such bugs (for example, the following code). However, running in Firefox is no problem. Or Firefox good ah, hehe!
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 to be matched: ' + i + '! ');
}
}
for (var i=0xff; i<=0xffff; i++) {
var s = string.fromcharcode (i);
if (!re.test (s)) {
Alert (' Should be matched: ' + i + '! ');
}
}