-
-
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
Arrays and Regex Substition Strings #15069
Comments
The issue is that in |
After kicking it around with the guys in the IRC channel, we discovered the cause was the promotion, as yuyichao commented. We also found that it could be worked around with |
We also discovered how to avoid the promotion: using |
that sounds like a bug in the way |
This is an interesting issue. Two possible solutions occur to me:
I'm not sure that SubstitutionString really should be a kind of AbstractString. A string represents a sequence of characters; what character is |
Changing promotion rules sounds like a good idea. It seems natural to promote standard strings to As regards inheriting from |
str = "tough";
f = r"(^[crt])ough";
t = s"\1ou2f";
replace(str, f, t) # throw
replace(str, f => t)
z = [f,""];
y = [t,""];
replace(str, z[1] => y[1])
replace(str, z[1] => t)
replace(str, f => y[1]) julia> str = "tough";
julia> f = r"(^[crt])ough";
julia> t = s"\1ou2f";
julia> replace(str, f, t) # throw
ERROR: MethodError: no method matching replace(::String, ::Regex, ::SubstitutionString{String})
Closest candidates are:
replace(::Union{Function, Type}, ::Any; count) at set.jl:605
replace(::String, ::Pair{var"#s75", B} where {var"#s75"<:AbstractChar, B}; count) at strings/util.jl:513
replace(::String, ::Pair{var"#s72", B} where {var"#s72"<:Union{Tuple{Vararg{AbstractChar, N} where N}, Set{var"#s53"} where var"#s53"<:AbstractChar, AbstractVector{var"#s54"} where var"#s54"<:AbstractChar}, B}; count) at strings/util.jl:518
...
Stacktrace:
[1] top-level scope
@ REPL[33]:1
julia> replace(str, f => t)
"tou2f"
julia> z = [f,""];
julia> y = [t,""];
julia> replace(str, z[1] => y[1])
"tou2f"
julia> replace(str, z[1] => t)
"tou2f"
julia> replace(str, f => y[1])
"tou2f" Related pr: |
So the
Whether related to this change or otherwise, the original problem seems to have been fixed in the intervening years
So I think we can finally close this! |
I'm new to the language, so can't be confident, but I was pointed to submit this issue by the #julia IRC channel. I couldn't find a reference to this behaviour in the issues listed here or on the mailing list.
The bug (if that is what it is) appears to be with subsitution strings when the substitution string is placed inside arrays.
The same behaviour appears if you do e.g.
y = [s"\1ou2f",""]
, and the use of\g<1>
rather than\1
does not resolve it. I would guess that the capture group is not being passed to the substitution string at all (\0
similarly produces\0ou2f
in the above).Version Info:
The text was updated successfully, but these errors were encountered: