I am using a regular expression to rewrite some URLs. I need to replace all ampersands & in a URL with & but not when the ampersand already starts an & occurrence. So I ended up with this:
search: (^[^&]*?)&((?!amp;)[^W]*?.htm)
replace: $1&$2
Which transformed:
Bob_&_Carol.htm
into:
Bob_&_Carol.htm
But this only works with the first ampersand and fails on multiple ampersands only converting the first occurrence.
Bob_&_Carol_&_Alice.htm
into:
Bob_&_Carol_&_Alice.htm
So I modified the match expression to find the multiple ampersands:
^(?:([^&]*?)&(?!amp;))*([^W]*?.htm)
But I have no idea how to write the Replace string to handle the multiple captures. How do I write the replacement string to replace all captures?