Skip to content

Commit 5201edd

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 d7b82f2 commit 5201edd

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

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

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

0 commit comments

Comments
 (0)