-
-
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
create a Regex from a string matching this string literally (with escaping) #31989
base: master
Are you sure you want to change the base?
Conversation
I don't think this should pun on |
It didn't strike me as a pun... do you see |
It is pretty weird that e.g. this would not be an error anymore: julia> r = [r"a", r"b"]
2-element Array{Regex,1}:
r"a"
r"b"
julia> push!(r, "c")
ERROR: MethodError: Cannot `convert` an object of type String to an object of type Regex |
Yeah, this should in my opinion use some kind of constructor. |
8f50fe4
to
436cac2
Compare
I renamed the function to |
Perhaps it is worth updating the title of the PR? |
Regarding naming, this is a bit different than
The proposed functionality is more like I would argue that I named So how can we get there? |
Oh, another "oops" is that the actual inverse of |
It's fairly unlikely scripts should be using |
As mentioned in #29643, it might be worthwhile to have a function for producing a string or string-like object with escapes in place, as this could have other uses (e.g., further manipulation) than simply searching directly. Producing the regex directly is mainly an optimization, which could be a variant of the function or which one could handle just like compiling regexen in general? Just a thought. |
No worries, I'm glad that you look into the issue. I'm not familiar with the other stringy functions so can't contribute to the naming discussion right now, but will happily trust your judgment :)
I didn't expect it would be needed, but thank you for mentioning this point. It's currently possible via |
Good point, @mlhetland: I actually think that |
I should probably open a separate issue for the |
I agree, thats what we have in Documenter: https://github.com/JuliaDocs/Documenter.jl/blob/22639383221b89921e44a93650080efda807fc36/src/Utilities/Utilities.jl#L13 + https://github.com/JuliaDocs/Documenter.jl/blob/22639383221b89921e44a93650080efda807fc36/src/Utilities/Utilities.jl#L23-L24 |
EDIT:
convert(Regex, s)
renamed toescape_regex(s)
. I like to believe that two thumbs-down were due to the old name.This was suggested by @StefanKarpinski, so putting it here for discussion. Currently, the way to match a string
s
exactly is to writer"" * s
, with this PR we can now writeconvert(Regex, s)
, which is more direct, if not terser or much faster.