I'm trying to hack about some sidebar code in a Wordpress template I'm developing. Basically I've captured what I need in an output buffer and I'm running regex over it to replace bits with the code I need. Problem is my regex knowledge is just a bit short on what I need to achieve.The problem I'm having is as such:\[code\]$output = preg_replace('/<\/li><li id=".*?" class="widget-container/', '<a href="http://stackoverflow.com/questions/3365267/top">Top</a></li><li><li id="[item from that find]" class="widget-container/', $input);\[/code\]At the moment as the code stands I can find what I need but it destroys those id attributes as I can't capture them.I'm sure there is a way I can do this to capture and use it in the replacement but I can't find anything that tells me what I need or if I'm taking the wrong approach with preg_replace.How can I use this to change code without destroying those unique ids?Cheers guys!