I have an XML code and I want to replace something in it.
If there is "\\d{4}s</w:t>"
I want to replace the LAST occurrence of "<w:rPr>"
before this with "<w:rPr><w:keepNext/>"
and I don't know how.
What I tried is "str_replace_all(Text, "(<w:rPr>.*?)(\\d{4}s</w:t>)", "\\1<w:keepNext/>\\2")"
but this does not replace the last occurrence of "<w:rPr>"
.
I asked a similar question before but it was closed because it was too similiar to Find shortest matches between two strings. But this did not help me.
EDIT:
Here is a similar example:
str_replace_all("hallohallohallo text bye hallohallo text2 bye", "(hallo)(.*?bye)", "\\1,\\2")
leads to "hallo,hallohallo text bye hallo,hallo text2 bye"
and I want "hallohallohallo, text bye hallohallo, text2 bye"