# findlasttext proc

Source: https://ref.dm-lang.org/proc/findlasttext
Added in BYOND 510.

### Format
> `findlasttext(Haystack,Needle,Start=0,End=1)`

### Returns
> The last position of Needle in Haystack; 0 if not found.

### Args
- `Haystack`: The text string to search.
- `Needle`: The sub-text to search for.
- `Start`: The text byte position in Haystack in which to begin the search. Because this searches backwards, the default is the end of the string (0).
- `End`: The earliest position in Haystack that can be matched as a result.


This instruction is NOT sensitive to the case of Haystack or Needle. The case-sensitive version is findlasttextEx().

If the start or end position is negative, the position is counted backwards from the end of the string. E.g., findlasttext("Banana", "na", -3) starts three characters from the end and will skip over the last "na".

> [!note]
> 
> Unlike findtext(), a regular expression may NOT be used as the Needle. Searching backwards is simply too complex for the regular expression engine.

> [!note]
> 
> In strings containing non-ASCII characters, byte position and character position are not the same thing. Use `findlasttext_char()` to work with character counts instead of bytes, at a performance cost. See the [Unicode](https://ref.dm-lang.org/notes/Unicode.md) section for more information.

### See also
- [findtext proc](https://ref.dm-lang.org/proc/findtext.md)
- [findtextEx proc](https://ref.dm-lang.org/proc/findtextEx.md)
- [findlasttextEx proc](https://ref.dm-lang.org/proc/findlasttextEx.md)
