删除所有斜杠正则表达式

Joh*_*hnA 4 php regex replace

我有字符串"h///e/ll\\o\//\".需要多次从其中来回删除所有斜线可以有人向我显示正则表达式吗?

它用于php preg_replace();

Pet*_*tah 6

试试这个:

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

http://codepad.org/PIjKsc9F

或者替代地

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

http://codepad.org/0d5j9Mmm


cmb*_*ley 5

您不需要正则表达式来删除这些:

$string = str_replace(array('/', '\\'), '', $string);
Run Code Online (Sandbox Code Playgroud)