1. Perl
  2. builtin functions
  3. here

rindex function - Search for a string from the end

Use the rindex function to search for a string from the end of the string .

my $pos = rindex($target, $str);

index function searches for a string from the beginning, while the rindex function searches for a string from the end. In the first argument, specify the string to be searched, and in the second argument, specify the string you want to search. You can specify the search start position in the third argument. If omitted, the search will be performed from the end of the string. If found, that position is returned, otherwise -1 is returned.

Programming example using rindex function

This is a programming example using the rindex function.

# Search for characters from the end of the string
my $message = "love love love.";
my $word_love_pos_last = rindex($message, 'love');

Related Informatrion