Reputation: 1913
I have string "h///e/ll\\o\//\"
.
Need to remove all slashes from it back and forth slashes multiple times can someone show me regex to do this?
its for php preg_replace();
Upvotes: 4
Views: 7397
Reputation: 46040
Try this:
var_dump(preg_replace("@[/\\\]@", "", "h///e/ll\\o\\//\\"));
// Output: string(5) "hello"
Or alternativly
var_dump(str_replace(array('\\', '/'), '', 'h///e/ll\\o\\//\\'));
// Output: string(5) "hello"
Upvotes: 6
Reputation: 42458
You don't need a regex to remove these:
$string = str_replace(array('/', '\\'), '', $string);
Upvotes: 5