-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behavior
Description
This is a repost from my question on discourse but I'm reasonably sure it's a bug so opening here. Everything below is ran with the most recent 1.2 binary on mac FWIW.
What fails:
replace("The quick fox run quickly.", r"fox(es)?" => s"bus\1")
Stacktrace:
ERROR: PCRE error: requested value is not set
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] substring_length_bynumber at ./pcre.jl:155 [inlined]
[3] _write_capture(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Regex, ::Int64) at ./regex.jl:286
[4] _replace(::Base.GenericIOBuffer{Array{UInt8,1}}, ::SubstitutionString{String}, ::String, ::UnitRange{Int64}, ::Regex) at ./regex.jl:320
[5] #replace#327(::Int64, ::Function, ::String, ::Pair{Regex,SubstitutionString{String}}) at ./strings/util.jl:459
[6] replace(::String, ::Pair{Regex,SubstitutionString{String}}) at ./strings/util.jl:447
[7] top-level scope at none:0
Note this example is adapted from the doc of replace
just changing foxes
(in the doc) for fox
. So in this case the optional matching group does not match which is what the error says about \1
not being set. The expected behaviour should be to just get "The quick bus run quickly."
i.e. the \1
should be injected with an empty string, I think.
FWIW, using Python 3.7:
import re
re.sub(r"fox(es)?", r"bus\1", "The quick fox run quickly.")
# 'The quick bus run quickly.'
Metadata
Metadata
Assignees
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behavior