Skip to content

lastIndexOf

Module Export

text |> (pattern: regex | text) => number

Returns the index of the last occurrence of the pattern in a texgt

lastIndexOf finds the last occurrence of pattern in the input text and returns the index of the first character. If pattern is not found, -1 is returned.

Examples

Find using a text pattern

import { lastIndexOf } from 'text'
from 'This is a sentence' lastIndexOf ' is '
// Returns:
4

Find using a regex pattern

import { lastIndexOf } from 'text'
from 'This is a sentence' lastIndexOf / \w /
// Returns:
7