Fix regex casefolding for regexes with trailing \

These expressions are invalid, but casefolder converted them into
"\\\0" and caused an out-of-bound read.