regex
regex copied to clipboard
`shortest_match` does not match *shortest*
What version of regex are you using?
1.4.3
Describe the bug at a high level.
The name shortest_match
is misleading. It suggests the method will return shortest possible match. In reality that’s not the case. While I accept that it may be infeasible to change the code to make such guarantee, the name of the method should be changed. fastest_match
? match_end
?
What are the steps to reproduce the behavior?
extern crate regex;
use regex::Regex;
fn main() {
println!("{}", Regex::new("ab|a").unwrap().shortest_match("ab").unwrap());
}
What is the actual behavior?
Prints 2.
What is the expected behavior?
Prints 1.
Indeed. A better name I think is leftmost_first
, but it is a bit more arcane I think.
With that said, I am not sure that the current behavior is correct either. It requires an investigation. I would naively assume that your program prints 1.