How to create correct preg_replace pattern?


I have these urls in my magento store:  charogh/product/1298/productname  the productname will be change for each productthe correct structure is:  charogh/product/[0-9]+/[a-zA-z0-9]+

I should change and replace 'product/[0-9]+/' with '' and make the url to 'charogh/' when user enter this url   'charogh/product/[0-9]+/'  and do not replace it when user enter this url  'charogh/product/[0-9]+/productname'  how can i do it with preg_replace or preg_match?

I use this pattern but it replace in both structures  $header=preg_replace('//charogh/product/[0-9]+/'"charogh