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

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -