Delete all cutting slashes

I have the line "h///e/ll\\o\//\" . You need to remove all slashes from it back and forth slashes several times, can anyone show me a regex to do this?

its for php preg_replace ();

+4
source share
2 answers

Try the following:

 var_dump(preg_replace("@[/\\\]@", "", "h///e/ll\\o\\//\\")); // Output: string(5) "hello" 

http://codepad.org/PIjKsc9F

Or alternatively

 var_dump(str_replace(array('\\', '/'), '', 'h///e/ll\\o\\//\\')); // Output: string(5) "hello" 

http://codepad.org/0d5j9Mmm

+6
source

You do not need regex to remove them:

 $string = str_replace(array('/', '\\'), '', $string); 
+5
source

Source: https://habr.com/ru/post/1396529/


All Articles