Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method longest_match #791

Closed
symil opened this issue Jul 2, 2021 · 3 comments
Closed

Method longest_match #791

symil opened this issue Jul 2, 2021 · 3 comments

Comments

@symil
Copy link

symil commented Jul 2, 2021

There is is_match that checks if there is a match for the given string, there is shortest_match that checks if there is a match and returns the length of the shortest match, but no method that checks if there is a match and returns the length of the longest match.

Re-using the shortest_match example, we would have:

let text = "aaaaa";
let pos = Regex::new(r"a+").unwrap().longest_match(text);
assert_eq!(pos, Some(5));
@symil symil changed the title Missing method longest_match Method longest_match Jul 2, 2021
@BurntSushi
Copy link
Member

BurntSushi commented Jul 2, 2021

That's what find does.

(Well, technically find is "leftmost-first" or "preference-order." This crate doesn't implement POSIX "leftmost longest" semantics.)

@BurntSushi
Copy link
Member

And note also that shortest_match is perhaps not the best name: #747

@symil
Copy link
Author

symil commented Jul 3, 2021

I was confused about what shortest_match did, sorry. I thought it stopped if the first character of the string didn't match the regex (and I thought the same about is_match). I suggest to change the example of shortest_match and have text be "baaaa" to illustrate that it's not the case. That would help clear the confusion for noobs like me who just discovered the crate.

Again sorry for the useless issue and thanks for the precision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants