regex - Backslashes in regexp pattern for PHP -
i'm trying perform regex operation in php code (preg_replace). i'm working with:
|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i that matches urls http://google.com, etc... i'm guessing if url want match one?
http:\/\/asd.domain.com\/path\/of\/url\/something.else i've tried 2x backslashes , 4x backslashes , doesn't seem work.
any advice?
thanks in advance.
well, if want match string, add backslashes:
^http(s)?:\\?/\\?/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\\?/.*)?$ i used ? quantifier still matches urls match before that. since \ escaping character, need 2 of those, first escape escaping properties of second \.
see demo (i escaped forward slashes there because of how regex tester works -- delimiters slashes).
Comments
Post a Comment