A continuation of my previous question…
After testing the text format, if it is not the correct format I would like to figure out which pairs of hex values are incorrect (i.e. any pair that contains value(s) other than[0-9A-Fa-f]).
if( validFormat ) {
// do processing
}
else {
// find invalid hex value pairs
}
What is the most efficient way to obtain a list of incorrect(invalid) hex pairs so that I can report back the errors and their associated hex pairs.
Edit for additional question
Also, how would I go about testing to ensure there is not a “double space” anywhere, because that also constitutes for invalid format even though the hex pairs may be valid.
Thanks!
The easiest is to find all values and scan for those that are not valid:
That regex says:
^starting at the beginning of the string[0-9a-f]find any character that is a digit or a-f{2}find exactly two of them$making sure that we are now at the end of the stringiand make it case-insensitive (allow A-F as well as a-f)With the above you can then do:
Edit: If you explicitly want to test that the string contains nothing but single-byte hex strings separated by a single space, the simplest test would just be: