You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
replace_all in the regex crate replaces empty strings before non-matching characters differently than Python's standard library regex engine. (Rust version of regex doesn't consider empty strings before non-matching characters as valid matches.)
What are the steps to reproduce the behavior?
Create a Regex object with the pattern r"a*" (matches zero or more "a"s).
Apply replace_all to the string "abxd" with a hyphen as the replacement string.
Observed output (Rust): "-a-b-d-"
Expected output (Python): "-a-b--d-"
Rust Code
use regex::Regex;fnmain(){let re = Regex::new(r"x*").unwrap();let hay = "abxd";println!("{:?}", re.replace_all(hay,"-"));}
What version of regex are you using?
v1.10.3
Describe the bug at a high level.
replace_all
in the regex crate replaces empty strings before non-matching characters differently than Python's standard library regex engine. (Rust version of regex doesn't consider empty strings before non-matching characters as valid matches.)What are the steps to reproduce the behavior?
r"a*"
(matches zero or more "a"s)."abxd"
with a hyphen as the replacement string."-a-b-d-"
"-a-b--d-"
Rust Code
Equivalent Python Code:
What is the actual behavior?
replace_all
only replaces the empty string before"b"
in Rust, not the one before"d"
.What is the expected behavior?
Both empty strings should be replaced, resulting in
"-a-b--d-"
.By the way, I am not sure, if this is an intentional difference or a potential bug?
The text was updated successfully, but these errors were encountered: