If in php (preg_replace did you say?), You can use preg_replace_callback:
preg_replace_callback('#(&[a-z0-9]+)?;\)#i', 'myFunction', 'myText');
in the "myFunction" function, you just need to check if there is any html element in the capture bracket.
function myFunction($matches) { if(!empty($matches[1]) { return $matches[0]; } return '[Smilie]'; }
source share