JohnA
JohnA

Reputation: 1913

remove all slashes regex

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

Answers (2)

Petah
Petah

Reputation: 46040

Try this:

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

http://codepad.org/PIjKsc9F

Or alternativly

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

http://codepad.org/0d5j9Mmm

Upvotes: 6

cmbuckley
cmbuckley

Reputation: 42458

You don't need a regex to remove these:

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

Upvotes: 5

Related Questions