php - strip multiple trailing dashes and numbers from string -


i want strip trailing dashes , numbers file name.

filename: filename-01-1 , filename-01 

my code works fine when file name in second format.

rtrim(preg_replace("/\d+$/","",$filename),'-') 

also tried

rtrim(preg_replace('/[0-9]+/',"",$filename),'-') 

any appreciated.

preg_replace("/(-|\d+)*$/",'', $filename); 

explaination

(-|\d+) # match "-" literally or digit *       # match previous group 0 or more times  $       # end of string 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -