It depends. I assume that your real string and real pattern are something else than 'abababa' and 'b'. Something that might not be easily reversable. What if your string is 'abbabba', and your pattern 'b+', to be replaced with 'x'. Should that result in 'abbaxa', or 'abbabxa'? Simply reversing the string and pattern, as suggested by some, will give you 'abbaxa', but the right most subpattern that matches 'b+' is the last b in the string.