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.
The following are the referenced contents:
Copy Code code as follows:
Regex 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 wasn't 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 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!
The following are the referenced contents:
Copy Code code as follows:
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 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 + '! ');
}
}