SQLite Forum

Hidden noCase bug in ext/misc/regexp.c in pRe->zInit prefix optimization
Hello! I'm trying to modify `regexp.c` extension for my application. So I added 3-args `regexp(re, text, noCase)` function.

I'm noticed, that queries like  

> select regexp('abc', 'ABC', 1);

> select regexp('ABC', 'ABC', 1)

doesn't match.

But `select regexp('ABC', 'abc', 1)` matches.

I found out that it is because of the prefix optimiation in re_compile in lines [668-691](https://www.sqlite.org/cgi/src/file?ci=trunk&name=ext/misc/regexp.c&ln=668-692). 

Upper, when calling [re_subcompile_re at 651](https://www.sqlite.org/cgi/src/file?ci=trunk&name=ext/misc/regexp.c&ln=651), the text of the regular expression is written in lowercase, so the prefix is stored in lowercase.

Then in re_match at line [217](https://www.sqlite.org/cgi/src/file?ci=trunk&name=ext/misc/regexp.c&ln=217) the prefix is compared with text *case-sensitive*.

The simplest way to fix it - disable prefix optimization in noCase mode - modify line [676](https://www.sqlite.org/cgi/src/file?ci=trunk&name=ext/misc/regexp.c&ln=676) from

> if( pRe->aOp[0]==RE_OP_ANYSTAR ){


> if( !noCase && pRe->aOp[0]==RE_OP_ANYSTAR ){