Problem with regex example in docs

I’m trying the code in the Regex section, but I am getting an error. Anyone know what I am doing wrong?

julia> m = match(r"(a|b)(c)?(d)", "ad")
RegexMatch("ad", 1="a", 2=nothing, 3="d")

julia> first, second, third = m; first
ERROR: MethodError: no method matching iterate(::RegexMatch)
Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
  iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
  iterate(::T) where T<:Union{Base.KeySet{var"#s77", var"#s76"} where {var"#s77", var"#s76"<:Dict}, Base.ValueIterator{var"#s75"} where var"#s75"<:Dict} at dict.jl:693
  ...
Stacktrace:
 [1] indexed_iterate(I::RegexMatch, i::Int64)
   @ Base ./tuple.jl:89
 [2] top-level scope
   @ REPL[29]:1

julia> 

Also, as an aside, where do I file a bug for a typo in the docs?

As a convinience

should be, of course, convenience

For the second, I’m sure a PR will be much appreciated (I’m not sure where you’re seeing this though? if you can find the location on the Julia repo say a docstring or something then you can directly edit it there and propose the change)

For the first, use .captures

julia> m = match(r"(a|b)(c)?(d)", "ad")
RegexMatch("ad", 1="a", 2=nothing, 3="d")

julia> f, s, t = m.captures
3-element Vector{Union{Nothing, SubString{String}}}:
 "a"
 nothing
 "d"

PS (nitpicking): first is a function in Julia so probably best not to use it as variable name.

2 Likes

FWIW, your code works fine on Julia 1.7 and newer.

3 Likes

It is the code in the docs here:

https://docs.julialang.org/en/v1/manual/strings/#man-regex-literals

Which is also where the typo is.

And yeah, I guess I am using 1.6.4. Surprised the Arch package isn’t updated yet. Oh wait, it was updated a couple days ago! Time to update my system.