If you're matching a simple string (e.g. 'b'), as opposed to a general regexp pattern, then I think the rindex solution proposed by Transient and Animator is the way to go. For more complicated matches, you could use a negative look-ahead assertion to single out the last occurrence; e.g. to replace the last occurrence of the pattern /[AB]/ with X, you could use
This will replace the last occurrence of A or B with X. The /s modifier is necessary in case the string contains embedded newlines.s/[AB](?!.*[AB])/X/s
the lowliest monk
In reply to Re^3: matching operator question
by tlm
in thread matching operator question
by redss
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |