Regular Expressions and the Transformer function

I'm looking to find a way that allows me to use either the copy and replace or the javascript transformer features to make it so that when I highlight a section of code, I can then highlight the area that I want to paste it to and it will put the copied item around that new area. Example is probably easier to show:

Step 1:
{p}History of Dogs and Cats{/p} I highlight this and click cmd+c

Step 2:
A Discussion on Rocks I then highlight this and click cmd+v

Step 3:
{p}A Discussion of Rocks{/p} This is the result

*Antyhing I put in angled brackets doesn't show up, so I'm using { } these instead, but ideally it will be between the pac man symbols
I think this can be done one of two ways (neither of which I know enough about to do myself)

  1. When you are pasting the copied item on the highlighted text you are trying to surround the code with, you can use regular expressions that looks for everything up to the first > symbol and puts that before the highlighted text and then next look for the following < symbol and have that and anything after it be pasted after the highlighted text, so it ends up surrounding it.
  2. Use the javascript transformer in some way that does this easier that I don't know?

Any help would really be greatly appreciated and anyone who writes code will I'm sure understand how useful this code be for them!

THANKS!