Skip to content

Commit 7ed6ba1

Browse files
committed
Document known REGEXP differences from MySQL
List the differences that stay on purpose, because fixing them would take a pattern translator, or more code than such rare input is worth: ICU-only syntax, CRLF, ICU sets, hyphens after classes, numeric text and arguments, inline case flags, and \u escapes in replacements.
1 parent e19fe0c commit 7ed6ba1

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,15 @@ public function _helper_like_to_glob_pattern( $pattern ) {
12041204
* only the former and errors on the latter.
12051205
* - ICU supports multi-code-point case folds such as "ß" matching "ss";
12061206
* PCRE's case-insensitive mode does not.
1207+
* - ICU-only syntax, such as `\uXXXX` and `\N{name}` in patterns, is an error.
1208+
* - ICU reads CRLF as one line break, and PCRE as two characters. `$` also
1209+
* matches between them, and `.` with the `n` flag matches only one of them.
1210+
* - ICU's nested sets and set operations don't exist in PCRE. `[a[b]]` and
1211+
* `[a&&b]` silently match something else, and `[a--b]` is usually an error.
1212+
* - A hyphen after a POSIX class or a property, as in `[[:alpha:]-z]` or
1213+
* `[\p{L}-x]`, is an error. ICU reads it literally.
1214+
* - A POSIX class outside of a set, as in `[:alpha:]`, is usually an error. ICU
1215+
* reads it like `[[:alpha:]]`.
12071216
*
12081217
* Known limitations of this emulation:
12091218
*
@@ -1214,7 +1223,17 @@ public function _helper_like_to_glob_pattern( $pattern ) {
12141223
* - The `u` (UTF-8) PCRE modifier is applied to REGEXP_* functions, so
12151224
* they reject data that is not valid UTF-8 from the start position on.
12161225
* The REGEXP operators match such data, and REGEXP BINARY, byte by byte,
1217-
* like MySQL binary strings.
1226+
* like MySQL binary strings. Binary values that are valid UTF-8 match as
1227+
* text, so case sensitivity can differ between rows.
1228+
* - SQLite converts float and decimal operands to text, in a different format
1229+
* from MySQL: `20e0` reads "20.0" (MySQL: "20"), `0.000001` reads "1.0e-06",
1230+
* and `1.50` reads "1.5". Integers above the BIGINT range read as floats.
1231+
* - `pos`, `occurrence`, and `return_option` use PHP's integer conversion, so
1232+
* `2.6` means 2 (MySQL: 3), and `'2e1'` means 20 (MySQL: 2).
1233+
* - Inline case flags don't reach [:upper:] and [:lower:], or \p{Lu} and
1234+
* \p{Ll} on PCRE 10.44 and older. They stay case-sensitive in
1235+
* `(?i)[[:upper:]]` with the `c` flag, and in the whole pattern when it
1236+
* contains "(?-i)".
12181237
*
12191238
* @param string $pattern The MySQL regex pattern.
12201239
* @param string $match_type MySQL match_type flag string.
@@ -1435,6 +1454,7 @@ private function regexp_char_to_byte_offset( $s, $char_pos, $allow_past_end = fa
14351454
*
14361455
* Rules (from ICU, used by MySQL REGEXP_REPLACE):
14371456
* - "\X" for any X: emit X, drop the backslash (also applies to "\\" -> "\").
1457+
* Unlike ICU, "\uXXXX" and "\UXXXXXXXX" are not expanded.
14381458
* - Trailing lone backslash: dropped.
14391459
* - "$N" (N is one or more digits): emit the Nth capture group. Consumes
14401460
* the longest digit run that forms a valid group index; any trailing

0 commit comments

Comments
 (0)