in reply to Match only last occurrence

Skip over everything with .*, then backtrack to the last occurence.

/\A.*^text: \d\d\d/ms

Replies are listed 'Best First'.
Re^2: Match only last occurrence
by BillKSmith (Monsignor) on May 31, 2016 at 19:44 UTC
    Great response! I did not notice it when I wrote and tested much the same thing.
    use strict; use warnings; use Test::Simple tests => 1; my $multi_line_string = "yadda text: 123 yadda yadda\n" . " text: 456 yadda\n" ; $multi_line_string =~ /\A .* (text\:\s\d{3}) /xms; my $expected = 'text: 456'; my $match = $1; ok( $match eq $expected, 'Match last occurrence'); OUTPUT: 1..1 ok 1 - Match last occurrence
    Bill