替换两个字符之间包含的字符串[关闭]

I have a string like:

www.mydomain.com/product/$ID_PRODUCT$/ID_$ID_PRODUCT$

what I need is replace strings contained between '$' and '$', also deleting the strings delimiters ( which is '$' ) obtaining something like:

www.mydomain.com/product/1234/ID_1234

Thanks,

EDIT: Trying

$new_string = preg_replace('/(\$)(.*)(\$)/s', product->id, $string);

But it does not handle the second expression...

The demo of @stribizhev , given in comments below, worked for me!

This seem to work:

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

Demo