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). We can see that the prefix stored as is (no case modification).

Then in re_match at line [212](https://www.sqlite.org/cgi/src/file?ci=trunk&name=ext/misc/regexp.c&ln=217) the prefix is compared 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 ){