martin-g commented on code in PR #19827:
URL: https://github.com/apache/datafusion/pull/19827#discussion_r2698066605
##########
datafusion/functions/src/regex/regexpreplace.rs:
##########
@@ -659,6 +661,28 @@ mod tests {
use super::*;
+ #[test]
+ fn test_regex_replace_posix_groups() {
+ // Test that \1, \2, etc. are replaced with ${1}, ${2}, etc.
+ assert_eq!(regex_replace_posix_groups(r"\1"), "${1}");
+ assert_eq!(regex_replace_posix_groups(r"\12"), "${12}");
+ assert_eq!(regex_replace_posix_groups(r"X\1Y"), "X${1}Y");
+ assert_eq!(regex_replace_posix_groups(r"\1\2"), "${1}${2}");
+
+ // Test double backslash (from SQL escaped strings like '\\1')
+ assert_eq!(regex_replace_posix_groups(r"\\1"), "${1}");
+ assert_eq!(regex_replace_posix_groups(r"X\\1Y"), "X${1}Y");
+ assert_eq!(regex_replace_posix_groups(r"\\1\\2"), "${1}${2}");
Review Comment:
nit: you may also add a test case with 3 or 4 backslashes before the number
to document the expected behavior in this case, e.g.:
```rust
assert_eq!(regex_replace_posix_groups(r"\\\1\\\\2"), "\${1}\\${2}");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]