-1

I have a string: http:\/\/example\.com

I try to regex this to be: http://example.com

I've used preg_replace('/\(\)/', '', $string) but it is not working.

Could you help me, please?

tamlevn
  • 3
  • 2

1 Answers1

-1

You should escape a backslash with another backslash to denote one literal backslash, but for the two backslashes to be passed to the regex parser after the interpretation of the compiler, you need to escape each backslash with another backslash:

preg_replace('/\\\\/', '', $string)

Demo: http://sandbox.onlinephpfunctions.com/code/39e6ffbe4fa5ee498754516fd7629a45bbfbe30e

blhsing
  • 91,368
  • 6
  • 71
  • 106