# findlast(pattern::Regex, string::String) missing?

**URL:** <https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562>\
**Category:** General Usage\
**Created:** [September 27, 2018, 2:40pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562 "2018-09-27T14:40:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [September 27, 2018, 2:40pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/1 "2018-09-27T14:40:31Z")

</div>

In Julia 1.0

```julia
julia> ?findlast

```

shows that the following method should exist.

```julia
findlast(pattern::Regex, string::String)

```

But 'methods(findlast)` shows no such method.

What needs to be corrected? The code in `Base` or the documentation?

---

<div class="post-metadata">

**Author:** ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)\
**Post date:** [September 27, 2018, 3:15pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/2 "2018-09-27T15:15:41Z")

</div>

The same problem exists for `findprev(patter::Regex, string::String, start::Integer)`

You could use `findfirst(r"pattern", reverse("string"))` in the mean time.

From the documentation of `reverse`:

> Reverses a string. Technically, this function reverses the codepoints in a string  
> and its main utility is for reversed-order string processing, especially for  
> reversed regular-expression searches.

Ok, reading the news entry: [https://github.com/JuliaLang/julia/blob/release-0.7/NEWS.md](https://github.com/JuliaLang/julia/blob/release-0.7/NEWS.md)  
It appears that those functions should be defined, but they aren’t.

@nalimilan : Could you help us on uncovering the truth?

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [September 27, 2018, 3:30pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/3 "2018-09-27T15:30:13Z")

</div>

> [@laborg](#):
>
> You could use `findfirst(r"pattern", reverse("string"))`

Provided you also reverse the pattern. I don’t know of any method that does that automatically.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [September 27, 2018, 3:40pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/4 "2018-09-27T15:40:33Z")

</div>

AFAIK we never had a function to apply a regex backwards. Reversing strings can help achieving that, but it’s always tricky.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 27, 2018, 4:54pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/5 "2018-09-27T16:54:53Z")

</div>

Finding a regex match from the end of a string is not something that most regex libraries support, as far as I’m aware. I don’t think PCRE (which we use) supports it, in particular.

---

<div class="post-metadata">

**Author:** ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)\
**Post date:** [September 27, 2018, 5:07pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/6 "2018-09-27T17:07:12Z")

</div>

So the right move is to remove the docstring relicts?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 27, 2018, 5:21pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/7 "2018-09-27T17:21:05Z")

</div>

The tricky thing is that we are able to do this for some types of needles, e.g. plain strings. For others, like regular expressions, we cannot do it. So this is unfortunately going to be a bit of a patchwork dues to implementation difficulties. But yes, that particular signature should be removed.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 27, 2018, 5:22pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/8 "2018-09-27T17:22:20Z")

</div>

> [@laborg](#):
>
> So the right move is to remove the docstring relicts?

Seems so to me.

---

<div class="post-metadata">

**Author:** ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)\
**Post date:** [September 27, 2018, 5:45pm UTC](https://discourse.julialang.org/t/findlast-pattern-regex-string-string-missing/15562/9 "2018-09-27T17:45:07Z")

</div>

[https://github.com/JuliaLang/julia/pull/29398](https://github.com/JuliaLang/julia/pull/29398)
