in reply to Match only last occurrence
The page is probably not huge. Just reverse it and let the regex find the first occurrence.
print reverse($1) . "\n" if reverse($string) =~ m/(\d{3} :txet)/;
If you wish to prevent strings of digits exceeding a length of 3, you can add a lookbehind:
m/(?<!\d)(\d{3} :txet)/
But now perhaps it's become ugly enough that reverse hasn't bought clarity.
Update: I can't recall where I first saw this technique. I thought maybe Mastering Regular Expressions, but a quick search of that text didn't turn up anything relevant. However, the notion of reversing a string as a quick and easy means of finding the last occurrence of some match in the string is discussed here: http://www.perl.com/pub/2001/05/01/expressions.html.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Match only last occurrence (sexeger)
by tye (Sage) on Jun 01, 2016 at 00:09 UTC | |
by davido (Cardinal) on Jun 01, 2016 at 00:52 UTC |