How to add a string only after the last match of a regex.replace (JavaScript)

I’m basically trying to reformat one string to another.
One of my functions can match certain areas of the original string and reformat them into a “properties” section which consists of “—” before and after it. I managed to add “—” before all the matches, but how would I go about only adding the second string after the last match of the replace function?

I tried many approaches but failed horribly. the closest I got was when it added “—” after the first match.