php - how to use preg_replace to replace all ocurrences of a given pattern? -


i have pattern (a slash followed 1 or more dashes) inside strings occur many times

/hi/--hello/-hi 

i want replace with

/hi/hello/hi 

i have tried

$str = preg_replace('/\/-+/', '/', $subject); 

but not seem working properly. missing something. use http://www.debuggex.com/ test regex , \/-+ not seem match string.

the reason doesn't work in debuggex.com don't have put delimiters on site.

remove slashes @ begining , @ end input box.

write only: \/-+ or /-+ since don't need escape slashes.


Comments