Repository navigation
Commit 973810c
authored
## Summary
This PR adds MySQL's `REGEXP_REPLACE()`, `REGEXP_SUBSTR()`, and
`REGEXP_INSTR()` functions, built on the REGEXP engine from WordPress#624. It
also enables their test suites from WordPress#622. Before, all 16,649 cases of
each suite failed, because the functions didn't exist. Now, these fail
on PHP 8.5:
- **`REGEXP_REPLACE()`:** 815 (MySQL cases: 276, ICU cases: 539).
- **`REGEXP_SUBSTR()`:** 790 (MySQL cases: 264, ICU cases: 526).
- **`REGEXP_INSTR()`:** 790 (MySQL cases: 264, ICU cases: 526).
Almost all of them also fail for `REGEXP_LIKE()` (766), mostly because
of ICU syntax that PCRE doesn't have.
It's the second of the PRs that split WordPress#368 into smaller chunks.
The main changes:
- **`REGEXP_REPLACE()`** replaces every match, or only a chosen one,
with MySQL's replacement syntax: `$1`, `${name}`, and backslash escapes.
- **`REGEXP_SUBSTR()`** returns a match, and **`REGEXP_INSTR()`**
returns where it starts or ends.
- **Positions** count characters in text, and bytes in binary data that
isn't valid UTF-8, like in MySQL.
- **Empty matches** move the search forward by one character, like in
MySQL. So `REGEXP_REPLACE('ab', '|a', '-')` returns `-a-b-`, where PHP's
`preg_replace()` would give `---b-`.
- **`\G` and `\K`** work like in MySQL: `\G` matches only where the
previous match ended, and `\K` is a literal "K". In PHP, `\K` in a
lookbehind could make a search loop forever.
- **Arguments** work like in MySQL 8.4: `pos` one past the end, a
negative `occurrence`, `NULL` arguments, and errors for invalid ones,
checked in MySQL's order.
## Why
Apps and plugins use these functions, and queries with them failed,
because the driver didn't support them.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
- **New Features**
- Added support for `REGEXP_REPLACE`, `REGEXP_SUBSTR`, and
`REGEXP_INSTR` in MySQL-compatible SQLite queries, including occurrence
selection, match positions, and replacement references.
- Regex operations now support binary data and character- or byte-based
positions, with improved handling of NULL values, match options, and
empty matches.
- **Tests**
- Expanded coverage for regex functions and enabled their compatibility
tests. Known differences are tracked across runtime versions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a7dc477 commit 973810c
6 files changed
Lines changed: 4195 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5396 | 5396 | | |
5397 | 5397 | | |
5398 | 5398 | | |
5399 | | - | |
5400 | | - | |
| 5399 | + | |
| 5400 | + | |
| 5401 | + | |
| 5402 | + | |
| 5403 | + | |
| 5404 | + | |
5401 | 5405 | | |
5402 | 5406 | | |
5403 | 5407 | | |
| |||
0 commit comments