RegExp help

Hi i’m trying to do a string replace with but can’t seem to get the regular expression right. Can anyone help me change “/portfolio/2/3/” to “portfolio_2_3”?

Basically I want to remove the leading and following slashes, and convert all the other slashes to underscores.

Thanks!