# Findfirst(r"\\d",tmp) works but : findlast(r"\\d",tmp) ERROR: MethodError: no method matching findlast(::Regex, ::String)

**URL:** <https://discourse.julialang.org/t/findfirst-r-d-tmp-works-but-findlast-r-d-tmp-error-methoderror-no-method-matching-findlast-regex-string/49688>\
**Category:** General Usage\
**Tags:** regex\
**Created:** [November 6, 2020, 4:56pm UTC](https://discourse.julialang.org/t/findfirst-r-d-tmp-works-but-findlast-r-d-tmp-error-methoderror-no-method-matching-findlast-regex-string/49688 "2020-11-06T16:56:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [November 6, 2020, 4:56pm UTC](https://discourse.julialang.org/t/findfirst-r-d-tmp-works-but-findlast-r-d-tmp-error-methoderror-no-method-matching-findlast-regex-string/49688/1 "2020-11-06T16:56:55Z")

</div>

What wrong ?

```julia
julia> tmp
"\":\"83 053 wyś"

julia> findfirst(r"\d",tmp)
4:4

julia> findlast(r"\d",tmp)
ERROR: MethodError: no method matching findlast(::Regex, ::String)
Closest candidates are:
  findlast(::Function, ::Union{AbstractString, AbstractArray}) at array.jl:2054
  findlast(::Function, ::Any) at array.jl:2046
  findlast(::AbstractString, ::AbstractString) at strings/search.jl:314
  ...
Stacktrace:
 [1] top-level scope at REPL[94]:100:

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 6, 2020, 5:20pm UTC](https://discourse.julialang.org/t/findfirst-r-d-tmp-works-but-findlast-r-d-tmp-error-methoderror-no-method-matching-findlast-regex-string/49688/2 "2020-11-06T17:20:26Z")

</div>

The underlying PCRE library that Julia uses for Regex searches does not support reverse-order searches, unfortunately.

The workaround is to **search the reversed string** (using a manually reversed regex as needed) and then use the `reverseind` function to compute the indices in the original string.

```julia
julia> tmp = "\":\"83 053 wyś"
"\":\"83 053 wyś"

julia> findfirst(r"\d",tmp)
4:4

julia> findfirst(r"\d",reverse(tmp))
6:6

julia> reverseind(tmp, 6)
9

julia> tmp[9]
'3': ASCII/Unicode U+0033 (category Nd: Number, decimal digit)

```

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [November 6, 2020, 5:26pm UTC](https://discourse.julialang.org/t/findfirst-r-d-tmp-works-but-findlast-r-d-tmp-error-methoderror-no-method-matching-findlast-regex-string/49688/3 "2020-11-06T17:26:16Z")

</div>

~~Another workaround wouldbe to use match:

```julia
julia> tmp=["123","abc","12ab"]
3-element Array{String,1}:
 "123"
 "abc"
 "12ab"

julia> findlast(x -> match(r"\d",x) != Nothing , tmp)
3

```

 ~~

~~But I didn’t check for performance differences, so I just let it there.  
 ~~  
Ok, doesnt work for strings. Never mind.
