Skip to content

Commit ea62949

Browse files
alambRich-T-kid
authored andcommitted
Minor: add tests for regexp_replace and capture groups (apache#21413)
## Which issue does this PR close? - related to apache#21379 ## Rationale for this change As suggested by @adriangb apache#21379 (comment) Let's add some additional test coverage as we work to optimize regexp_replace ## What changes are included in this PR? Add some tests ## Are these changes tested? yes ## Are there any user-facing changes? No
1 parent e905931 commit ea62949

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

datafusion/sqllogictest/test_files/regexp/regexp_replace.slt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,30 @@ from (values ('a'), ('b')) as tbl(col);
127127
----
128128
NULL NULL NULL
129129
NULL NULL NULL
130+
131+
# If the overall pattern matches but capture group 1 does not participate,
132+
# regexp_replace(..., '\1') should substitute the empty string, not keep
133+
# the original input.
134+
query B
135+
SELECT regexp_replace('bzzz', '^(a)?b.*$', '\1') = '';
136+
----
137+
true
138+
139+
# Stripping trailing .*$ must not change match semantics for inputs with
140+
# newlines when the original pattern does not use the 's' flag.
141+
query B
142+
SELECT regexp_replace(concat('http://x/', chr(10), 'rest'), '^https?://([^/]+)/.*$', '\1')
143+
= concat('http://x/', chr(10), 'rest');
144+
----
145+
true
146+
147+
# Inline multiline mode still allows only the matched prefix to be replaced.
148+
# The remainder of the string must be preserved.
149+
query B
150+
SELECT regexp_replace(
151+
concat('http://x/path', chr(10), 'rest'),
152+
'^(?m)https?://([^/]+)/.*$',
153+
'\1'
154+
) = concat('x', chr(10), 'rest');
155+
----
156+
true

0 commit comments

Comments
 (0)