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

findfirst , findlast and findall differences in needles #37350

Open
oxinabox opened this issue Sep 2, 2020 · 2 comments
Open

findfirst , findlast and findall differences in needles #37350

oxinabox opened this issue Sep 2, 2020 · 2 comments
Labels
domain:search & find The find* family of functions domain:strings "Strings!"

Comments

@oxinabox
Copy link
Contributor

oxinabox commented Sep 2, 2020

findfirst, findlast and findall each support a different set of needles when the haystack is an AbstractString.

findfirst(::Union{Regex, AbstractString, Function, AbstractChar}, ::AbstractString)
# Everything

findall(::Union{Regex, AbstractString, Function}, ::AbstractString)
# No AbstractChar

findlast(::Union{AbstractString, Function, AbstractChar}, ::AbstractString)
# No Regex

We should make them consistent

@nalimilan nalimilan added domain:search & find The find* family of functions domain:strings "Strings!" labels Sep 2, 2020
@nalimilan
Copy link
Member

See also findnext and findprev, which are respectively consistent with findfirst and findlast.

I'm not sure it's possible to get the last match of a regex with PCRE. That question may not be well-defined, as one can also write a regex to extract the last match of an expression, and pass that to findfirst. Of course as a brute-force method we could have findlast return last(findall(...)), but that's not a good implementation.

@stevengj
Copy link
Member

stevengj commented Sep 3, 2020

Yes, PCRE doesn't support reverse-order searching. (You can simulate by reversing the string and searching with a reversed regex, but automatically constructing a reversed regex in general seems to be a hard problem.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:search & find The find* family of functions domain:strings "Strings!"
Projects
None yet
Development

No branches or pull requests

3 participants