-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add method to contains for regex needle #18028
Conversation
…method is defined in `regex.jl`
widen signature to include char.
It seems to me like it would constitute a new feature, though that's of course up to one of the owners to decide.
We already have this functionality with the The method with Anyway, that's my $0.02. |
@ararslan you are correct, the functionality are there today. But from my point of view the current state is cluttered, as a test if a string contains a substring/regex/char requires different functions, see example:
From my point of view, Julia should unify this interface better using multiple dispatch. I would propose these three tests should use the same function and then deprecate all others. Then this is definitely first in 0.6. I do not care for the name or argument order. But i think the name should reflect the order.
From my perspective the best choice seem to unify on using
Python do also use in for characters and strings, but not for regex. |
Hm, I'm not so much a fan of using With this in mind, I think the current separation of
And at least IMO, But as I say often around these parts, my opinion here doesn't really matter since I'm just some guy, I just figured I'd state my position on it anyway, just in case. 😄 |
@ararslan, most of us are just "some guy/gal", and your opinion certainly counts, especially with your recent involvement. (IMHO, only uninformed and rudely expressed opinions count less, so I think you're safe...) I actually agree that, in general, a streamlined interface makes sense. However, my preference is probably to get rid of If we decide to keep it, though, I think this is a good change. |
I could see merging |
Sorry hit the wrong button. I see a regex as a way of specifying what you look for. As an example a regex could explain to look for a needle with a size of 4-5cm in the haystack. With this in mind I think it makes sense to use |
function contains(haystack::Union{SubString{String}, String}, re::Regex) | ||
compile(re) | ||
PCRE.exec(re.regex, haystack, start(haystack)-1, re.match_options, re.match_data) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just call ismatch(re, haystack)
?
I hadn't seen this PR when I opened #19250. Is there any chance you could move the docs changes to a separate PR (which should be straightforward to merge), then we can hash out the changes here? |
Bump. I think we should do two things here. (1) Merge |
From triage: |
Are we planning on replacing |
If it were up to me, I'd be tempted to rename |
|
@dhoegh Given what seems to be the consensus above, could you rebase the PR and keep only the changes deprecating |
I've added a commit merging |
This PR defines
contains
with a regex search pattern. Besides the new method I have also widen the signature of the original method to includeChar
as:contains(haystack::AbstractString, needle::Union{AbstractString, Char})
. Besides the additions tocontains
, I have:search
inlinesearch(::String, ::Regex)
fromtest/strings/search
totest/regex.jl
as the method is defined inregex.jl
.contains
and test for the methods plus additional tests forcontains
in general as it seemed not to be tested directly anywhere.It would be good to backport this to 0.5.1 as it increases test coverage and fixes docs. The additional methods for
contains
are probably not to be viewed as a "new" feature?