Repository navigation
Fix Oracle regexp newline matching semantics - #1489
Merged
gaoxueyu merged 4 commits intoAug 14, 2026
Merged
Conversation
Compile Oracle REGEXP_COUNT patterns with independent newline controls instead of adjusting match totals using every newline in the source. This keeps dot matching, negated character classes, and multiline anchors consistent with Oracle behavior. Add regression coverage for unrelated newlines, the m/n option matrix, negated bracket expressions, and multiline anchors. Assisted-by: OpenAI:gpt-5 Percentage of AI-generated code: 100% Signed-off-by: Rui <[email protected]>
Contributor
📝 WalkthroughWalkthroughOracle regular-expression handling now separates dot-newline matching from multiline anchors. ChangesOracle regular-expression newline semantics
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SQL caller
participant Oracle regexp flags
participant Regex compiler
participant Oracle regexp function
SQL caller->>Oracle regexp flags: Supply pattern and match parameters
Oracle regexp flags->>Regex compiler: Set REG_NLDOT and REG_NLANCH
Regex compiler->>Oracle regexp function: Produce newline-aware matches
Oracle regexp function->>SQL caller: Return count, position, substring, or replacement
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Collaborator
|
Thanks for contribution. We'll schedule a review for the patch. |
bigplaice
reviewed
Aug 4, 2026
Handle Oracle m and n match parameters in ora_parse_re_flags so REGEXP_COUNT, REGEXP_SUBSTR, REGEXP_INSTR, and REGEXP_REPLACE share the same dot and multiline-anchor semantics. Add regression coverage for the shared default, c, n, m, and mn behavior. Assisted-by: OpenAI:gpt-5 Percentage of AI-generated code: 100% Signed-off-by: Rui <[email protected]>
bigplaice
reviewed
Aug 7, 2026
bigplaice
reviewed
Aug 7, 2026
bigplaice
reviewed
Aug 7, 2026
Treat m and n as mutually overriding Oracle newline modes, with the last occurrence controlling dot and anchor behavior. This makes mn use n mode and nm use m mode across all shared regexp callers. Extend REGEXP_COUNT, REGEXP_SUBSTR, REGEXP_INSTR, and REGEXP_REPLACE regression matrices with default, c, n, m, mn, and nm coverage. Assisted-by: OpenAI:gpt-5 Percentage of AI-generated code: 100% Signed-off-by: Rui <[email protected]>
bigplaice
reviewed
Aug 7, 2026
Remove the unsupported last-option-wins interpretation for combined m and n match parameters. Keep m and n as independent controls for multiline anchors and dot-newline matching, and drop combined-mode expectations because Oracle behavior is not documented consistently. Retain default, c, n, and m coverage across REGEXP_COUNT, REGEXP_SUBSTR, REGEXP_INSTR, and REGEXP_REPLACE. Assisted-by: OpenAI:gpt-5 Percentage of AI-generated code: 100% Signed-off-by: Rui <[email protected]>
hs-liuxh
pushed a commit
to hs-liuxh/IvorySQL
that referenced
this pull request
Sep 2, 2026
…ewlines Fix Oracle regexp newline matching semantics (cherry picked from commit c3529ba)
hs-liuxh
pushed a commit
to hs-liuxh/IvorySQL
that referenced
this pull request
Sep 2, 2026
…ewlines Fix Oracle regexp newline matching semantics (cherry picked from commit c3529ba)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
REGEXP_COUNTtotals based on newlines outside the matchedsubstrings.
REG_NLDOT, which excludes newline from.without excluding it fromnegated bracket expressions.
mandnbehaviors centrally inora_parse_re_flags():menables multiline anchors, whilenallows dotto match newline.
REGEXP_COUNT,REGEXP_SUBSTR,REGEXP_INSTR,and
REGEXP_REPLACE, with regression coverage for default,c,n, andmmodes.Root cause
ora_regexp_count()counted every newline in the complete source and adjustedthe regex engine's result when the pattern began with
.or^. Newlinesoutside the matched substrings therefore changed the returned count.
PostgreSQL's newline-sensitive regex mode combines dot, bracket-expression,
and anchor behavior. Oracle's
mandnoptions control multiline anchorsand dot-newline matching separately. The existing
REG_NLSTOPflag could notprovide the required dot-only behavior because it also prevents negated
bracket expressions from matching newline.
This change adds a dot-specific regex flag and applies the Oracle option
semantics in the shared Oracle flag parser used by all four functions.
Review update
combined-option assertions and regression cases.
mandnas independent controls for their documented behaviors.PostgreSQL, HBA, JSONPath, or
REGEXP_LIKEpath is changed by the new flag.Validation
Run in the Docker development environment:
make -j2 -C contrib/ivorysql_ora oracle-check ORA_REGRESS=ora_character_datatype_functionsmake -j2 -C contrib/ivorysql_ora oracle-checkmake -j2 -C src/test/modules/test_regex checkmake -j2 checkmake -j2 oracle-check ORA_REGRESS=alter_index EXTRA_INSTALL=contrib/amchecktrailing newlines, negated classes, regex-cache isolation, the original
issue reproduction, and a 1,000-match stress case.
git diff --checkCloses #1481