There are a number of ways to do this, but the approach I've used in the past with something like this is to use a Third Party Plug In Action to do the heavy lifting.
The plug in is called Split
and you can download it from the Plug In Actions category of this forum; find it here:
Once you've installed it you can easily split out the bits from the URL and reassemble them. Here is a demo macro for you to use as a basis for your own solution.
Test Clean Amazon URL.kmmacros (3.8 KB)
This does depend entirely on the format of the Amazon URL being consistent, so if it isn't you'll have to modify this approach. Good luck!