The following patch works around the bug in grep which makes grep '[a-c]' match "B". Note, this is a bug in grep caused by a bug in the standards which do not provide interfaces to get the necessary information. This patch as correct as grep was before (multibyte char handling is not 100% correct but that cannot be solved now), future changes might increase the speed a bit. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- grep-2.4.2/src/dfa.c-old Sat Aug 19 17:55:05 2000 +++ grep-2.4.2/src/dfa.c Sat Aug 19 17:55:11 2000 @@ -743,6 +743,7 @@ lex (void) else c2 = c; +#if 0 lo[0] = c; lo[1] = '\0'; hi[0] = c2; hi[1] = '\0'; for (c = 0; c < NOTCHAR; c++) @@ -761,6 +762,37 @@ lex (void) } } } +#else + { + char expr[6] = { '[', c, '-', c2, ']', '\0' }; + regex_t re; + + if (regcomp (&re, expr, case_fold ? REG_ICASE : 0) + == REG_NOERROR) + { + for (c = 0; c < NOTCHAR; ++c) + { + char buf[2] = { c, '\0' }; + regmatch_t mat; + + if (regexec (&re, buf, 1, &mat, 0) == REG_NOERROR + && mat.rm_so == 0 && mat.rm_eo == 1) + { + setbit (c, ccl); + if (case_fold) + { + if (ISUPPER (c)) + setbit (tolower (c), ccl); + else if (ISLOWER (c)) + setbit (toupper (c), ccl); + } + } + } + + regfree (&re); + } + } +#endif skip: ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~