Skip to content

[Compatibility]: REGEXP lacks MySQL ICU constructs and capture-group replacement #28305

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

74668fc

Other Environment Information

- MatrixOne was built from the commit above and started locally with etc/launch/launch.toml.
- MySQL comparison version: 8.0.45.
- Every expression was repeated three times with the same result.

Actual Behavior

MatrixOne's REGEXP implementation rejects commonly used constructs accepted by
MySQL 8.0's ICU regular-expression dialect:

  • positive and negative lookahead: (?=...), (?!...);
  • positive and negative lookbehind: (?<=...), (?<!...);
  • pattern backreferences such as (a)\1;
  • atomic groups such as (?>a);
  • possessive quantifiers such as a++;
  • Unicode grapheme matching with \X.

The restriction affects the REGEXP operator, REGEXP_LIKE, REGEXP_INSTR,
REGEXP_SUBSTR, and REGEXP_REPLACE because they share the same underlying
matcher.

MatrixOne also treats the REGEXP_REPLACE replacement as literal text instead
of expanding MySQL capture references. For example:

SELECT REGEXP_REPLACE('ab','(a)(b)','$2$1');

returns the literal string $2$1 in MatrixOne, while MySQL returns ba.
The implementation explicitly calls ReplaceAllLiteralString or appends the
replacement text directly for occurrence-specific replacement.

POSIX character classes and Unicode properties such as [[:alpha:]]+ and
\p{L}+ work in both systems, so the difference is not a general Unicode or
REGEXP failure.

Expected Behavior

MatrixOne should implement the MySQL 8.0 ICU-visible pattern and replacement
semantics, or provide an equivalent compatibility layer. The examples below
all produce a match or transformed value in MySQL 8.0.45.

Steps to Reproduce

-- Lookaround assertions.
SELECT REGEXP_LIKE('ab','a(?=b)');
SELECT REGEXP_LIKE('ab','a(?!c)');
SELECT REGEXP_LIKE('ab','(?<=a)b');
SELECT REGEXP_LIKE('ab','(?<!c)b');

-- Backreference, atomic group, possessive quantifier, and grapheme.
SELECT REGEXP_LIKE('aa','(a)\\1');
SELECT REGEXP_LIKE('ab','(?>a)b');
SELECT REGEXP_LIKE('aaa','a++');
SELECT REGEXP_LIKE('😀','\\X');

-- The same dialect gap through other entry points.
SELECT 'ab' REGEXP 'a(?=b)';
SELECT REGEXP_INSTR('ab','a(?=b)');
SELECT REGEXP_SUBSTR('ab','(?<=a)b');
SELECT REGEXP_REPLACE('abc','(?<=a)b','X');

-- Replacement capture expansion.
SELECT REGEXP_REPLACE('ab','(a)(b)','$2$1');

-- Controls supported by both MatrixOne and MySQL.
SELECT REGEXP_LIKE('abc','[[:alpha:]]+');
SELECT REGEXP_LIKE('中文','\\p{L}+');

Additional information

MatrixOne compiles patterns with Go's regexp package in
pkg/sql/plan/function/func_builtin_regexp.go. Go regexp deliberately omits
lookaround, backreferences, atomic groups, and possessive quantifiers. The
replacement path uses literal replacement APIs and therefore also differs from
MySQL capture-reference behavior.

This is separate from #28304, which covers missing match_type parameters and
the u flag rather than pattern/replacement dialect semantics.

Activity

  1. added this to the MO-202609 milestone on Sep 7, 2026
  2. added
    kind/bug
    on Sep 7, 2026
  3. added theissue type on Sep 7, 2026
  4. self-assigned this
    on Sep 7, 2026
  5. XuPeng-SH commented on Sep 12, 2026

    @XuPeng-SH
    Contributor

    Partial capture-replacement follow-up: PR #28794 is open, stacked on PR #28787. It adds whole-match, numeric, and supported named capture expansion; unmatched captures are empty, template errors are lazy until a selected match exists, and binary captures preserve the source bytes.

    The UT and existing REGEXP_REPLACE BVT were extended for numeric/named references, escaping, occurrence and position boundaries, zero-width matches, binary NUL/invalid UTF-8, and prepared replacement values. The PR does not implement ICU-only pattern constructs (lookaround, pattern backreferences, atomic groups, possessive quantifiers, or grapheme matching). Please keep #28305 open for those remaining dialect gaps or split them into a separately designed follow-up.

    Local gofmt and diff checks pass. UT, BVT, and SCA were not run locally: the controlled test wrapper stopped before compilation because the isolated worktree lacks libmo.dylib and primary-worktree native-artifact provenance is unavailable; disk is critically low. Exact-head CI is required before merge.

  6. Ariznawlll commented on Sep 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • MatrixOne main:0c3a04f390adaf6281fd592a49778ea5b1155e67
    • 本地 standalone(1 CN / 1 TN / 1 LogService),2026-09-15。

    原问题验证

    验证 ICU lookahead/lookbehind、possessive quantifier 和编号捕获组替换;均按预期工作。

    Happy Path 覆盖

    覆盖 a(?=b)、(?<=a)b、a++a,以及 $1/$2 捕获组替换。

    Unhappy Path 覆盖

    possessive quantifier 不回溯的 a++a 返回不匹配;断言 lookbehind 的位置与子串结果。

    白盒验证

    MatrixOne func_regular_icu BVT 覆盖命名捕获 ${left} 替换;MOTR 解释器会展开 ${VAR},因此 MOTR 使用不被解释器吞掉的编号捕获替换,避免把测试框架限制误判为引擎行为。

    回归测试

    已加入 MOTR:issue_28305_icu_regexp,见 motr#176。

    测试证据

    新 MOTR 用例连续运行 3 轮成功;lookaround、possessive 与编号捕获替换均稳定通过。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions