TiDB supports most of the string functions available in MySQL 5.7, some of the string functions available in MySQL 8.0, and some of the functions available in Oracle 21.
Return the starting index of the substring that matches the regular expression (Partly compatible with MySQL. For more details, see Regular expression compatibility with MySQL)
The following sections describe the regular expression compatibility with MySQL.
Syntax compatibility
MySQL implements regular expression using International Components for Unicode (ICU), and TiDB uses RE2. To learn the syntax differences between the two libraries, you can refer to the ICU documentation and RE2 Syntax.
match_type compatibility
The value options of match_type between TiDB and MySQL are:
Value options in TiDB are "c", "i", "m", and "s", and value options in MySQL are "c", "i", "m", "n", and "u".
The "s" in TiDB corresponds to "n" in MySQL. When "s" is set in TiDB, the . character also matches line terminators (\n).
For example, the SELECT REGEXP_LIKE(a, b, "n") FROM t1 in MySQL is the same as the SELECT REGEXP_LIKE(a, b, "s") FROM t1 in TiDB.
TiDB does not support "u", which means Unix-only line endings in MySQL.
Data type compatibility
The difference between TiDB and MySQL support for the binary string type:
MySQL does not support binary strings in regular expression functions since 8.0.22. For more details, refer to MySQL documentation. But in practice, regular functions can work in MySQL when all parameters or return types are binary strings. Otherwise, an error will be reported.
Currently, TiDB prohibits using binary strings and an error will be reported under any circumstances.
Other compatibility
The difference between TiDB and MySQL support in replacing empty strings:
The following takes REGEXP_REPLACE("", "^$", "123") as an example:
MySQL does not replace the empty string and returns "" as the result.
TiDB replaces the empty string and returns "123" as the result.