Anchor to the right with the $ metacharacter. By anchoring to the right, and using a negative character class, you minimize the amount of work needed to find the last occurrence even if it's not the last thing in the string.
s/b([^b]*)$/x$1/Update:
And the following should yield better performance by using a positive lookahead assertion (eliminating the need for capturing parens), and still anchoring to the right.
s/b(?=[^b]*$)/x/
Dave
In reply to Re: RE - match from right
by davido
in thread RE - match from right
by bangers
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |