How to remove escaped forward slash using php?
php, regex
Solution
Avoid regex and just use `str_replace`:
$access_token = "1\/MgotwOvbwZN9MVxH5PrLR2cpvX1EJl8omgYdA9rrjx8";
$access_token = str_replace( '\/', '/', $access_token );
//=> 1/MgotwOvbwZN9MVxH5PrLR2cpvX1EJl8omgYdA9rrjx8
Problem
I am using the Google Drive API and the `refresh_token` I obtain has an escaped forward slash. While this should be valid JSON, the API won't accept it when calling `refreshToken()`. I am trying to remove the backslash using `preg_replace`: ``` $access_token = "1\/MgotwOvbwZN9MVxH5PrLR2cpvX1EJl8omgYdA9rrjx8"; $access_token = preg_replace('/\\\//', '/', $access_token); ``` I would like the returned string to be: ``` "1/MgotwOvbwZN9MVxH5PrLR2cpvX1EJl8omgYdA9rrjx8"; ``` I've tried various expressions, but it either doesn't remove the backslash or it returns an empty string. Note that I don't want to remove all backslashes, only the ones escaping a forward slash.