Skip to content

Commit ba1da19

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 7913ff4 commit ba1da19

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,13 @@ 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.
12071214
*
12081215
* Known limitations of this emulation:
12091216
*
@@ -1214,7 +1221,16 @@ public function _helper_like_to_glob_pattern( $pattern ) {
12141221
* - The `u` (UTF-8) PCRE modifier is applied to REGEXP_* functions, so
12151222
* they reject data that is not valid UTF-8 from the start position on.
12161223
* The REGEXP operators match such data, and REGEXP BINARY, byte by byte,
1217-
* like MySQL binary strings.
1224+
* like MySQL binary strings. Binary values that are valid UTF-8 match as
1225+
* text, so case sensitivity can differ between rows.
1226+
* - SQLite converts float and decimal operands to text, in a different format
1227+
* from MySQL: `20e0` reads "20.0" (MySQL: "20"), `0.000001` reads "1.0e-06",
1228+
* and `1.50` reads "1.5". Integers above the BIGINT range read as floats.
1229+
* - `pos`, `occurrence`, and `return_option` use PHP's integer conversion, so
1230+
* `2.6` means 2 (MySQL: 3), and `'2e1'` means 20 (MySQL: 2).
1231+
* - Inline case flags don't reach [:upper:] and [:lower:]. They stay
1232+
* case-sensitive in `(?i)[[:upper:]]` with the `c` flag, and in the whole
1233+
* pattern when it contains "(?-i)".
12181234
*
12191235
* @param string $pattern The MySQL regex pattern.
12201236
* @param string $match_type MySQL match_type flag string.
@@ -1426,6 +1442,7 @@ private function regexp_char_to_byte_offset( $s, $char_pos, $allow_past_end = fa
14261442
*
14271443
* Rules (from ICU, used by MySQL REGEXP_REPLACE):
14281444
* - "\X" for any X: emit X, drop the backslash (also applies to "\\" -> "\").
1445+
* Unlike ICU, "\uXXXX" and "\UXXXXXXXX" are not expanded.
14291446
* - Trailing lone backslash: dropped.
14301447
* - "$N" (N is one or more digits): emit the Nth capture group. Consumes
14311448
* the longest digit run that forms a valid group index; any trailing

0 commit comments

Comments
 (0)