<?php
$a = 'www.mydomain.com/product/$ID_PRODUCT$/ID_$ID_PRODUCT$';
echo preg_replace('/[$][a-zA-Z_]+[$]/',"1234",$a);