# Problem with regex example in docs

**URL:** <https://discourse.julialang.org/t/problem-with-regex-example-in-docs/72656>\
**Category:** New to Julia\
**Tags:** regex\
**Created:** [December 6, 2021, 2:03pm UTC](https://discourse.julialang.org/t/problem-with-regex-example-in-docs/72656 "2021-12-06T14:03:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdarnold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdarnold/32/31365_2.png) [@jdarnold](https://discourse.julialang.org/u/jdarnold)\
**Post date:** [December 6, 2021, 2:03pm UTC](https://discourse.julialang.org/t/problem-with-regex-example-in-docs/72656/1 "2021-12-06T14:03:23Z")

</div>

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

```julia
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?

```julia
As a convinience

```

should be, of course, convenience

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [December 6, 2021, 2:10pm UTC](https://discourse.julialang.org/t/problem-with-regex-example-in-docs/72656/2 "2021-12-06T14:10:49Z")

</div>

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
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.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [December 6, 2021, 2:23pm UTC](https://discourse.julialang.org/t/problem-with-regex-example-in-docs/72656/3 "2021-12-06T14:23:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jdarnold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdarnold/32/31365_2.png) [@jdarnold](https://discourse.julialang.org/u/jdarnold)\
**Post date:** [December 6, 2021, 5:34pm UTC](https://discourse.julialang.org/t/problem-with-regex-example-in-docs/72656/4 "2021-12-06T17:34:41Z")

</div>

It is the code in the docs here:

[https://docs.julialang.org/en/v1/manual/strings/#man-regex-literals](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.
