\\4\\5", $test); ?> outputs: hello www.domain1.com and http://domain2.com or https://domain3.com/asdf and domain4.com/file.html or www.domain5.com/file.html hello www.domain1.com and domain2.com ordomain3.com/asdf and domain4.com/file.html or www.domain5.com/file.html