Skip to content

Commit 226e10f

Browse files
committed
Document known REGEXP differences from MySQL
Point to the known failures of the REGEXP test suites for the syntax that ICU and PCRE read differently, instead of listing it. List the differences that the suites don't show: case folding, CRLF line breaks, and named groups in PCRE, and binary data and the text of numbers in SQLite.
1 parent 291fdc8 commit 226e10f

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

‎packages/mysql-on-sqlite/src/sqlite/class-wp-sqlite-pdo-user-defined-functions.php‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,24 +1047,19 @@ private function regexp_check_match_type( $function_name, $match_type ) {
10471047
* (UTF-8) modifier is applied unless byte-oriented matching is requested.
10481048
* Case-insensitive is the default.
10491049
*
1050-
* MySQL's native engine is ICU; we use PHP's PCRE. The two diverge in a
1051-
* few corners:
1052-
*
1053-
* - Some Unicode property shorthands and POSIX class spellings differ.
1054-
* - PCRE accepts both `(?<name>...)` and `(?P<name>...)`; MySQL accepts
1055-
* only the former and errors on the latter.
1056-
* - ICU supports multi-code-point case folds such as "ß" matching "ss";
1057-
* PCRE's case-insensitive mode does not.
1058-
*
1059-
* Known limitations of this emulation:
1060-
*
1061-
* - The default (case-insensitive) is correct for the usual
1062-
* `utf8mb4_0900_ai_ci` collation; callers that rely on a `_bin` or
1063-
* `_cs` collation must pass an explicit `c` match_type because this
1064-
* helper has no access to the session collation.
1065-
* - The `u` (UTF-8) PCRE modifier is applied to REGEXP_LIKE(), so it
1066-
* rejects data that is not valid UTF-8. The REGEXP operators match such
1067-
* data, and REGEXP BINARY, byte by byte, like MySQL binary strings.
1050+
* MySQL uses ICU, which differs from PCRE in some syntax, like ICU-only escapes
1051+
* and nested sets. The known failures of the REGEXP test suites list these
1052+
* cases. Other known differences:
1053+
*
1054+
* - Text matching ignores case unless the `c` flag is passed, as the column
1055+
* collation isn't known here.
1056+
* - PCRE doesn't match "ß" with "ss" when ignoring case, `$` also matches
1057+
* between CR and LF, and `(?P<name>...)` is valid.
1058+
* - REGEXP_LIKE() rejects data that isn't valid UTF-8. The REGEXP operators
1059+
* match it byte by byte and case-sensitively, and other binary values as
1060+
* text, so case sensitivity can differ between rows.
1061+
* - SQLite converts numbers to text in its own format, so `20e0` reads "20.0"
1062+
* (MySQL: "20"), and `0.000001` reads "1.0e-06".
10681063
*
10691064
* @param string $pattern The MySQL regex pattern.
10701065
* @param string $match_type MySQL match_type flag string.

0 commit comments

Comments
 (0)