Hi,
I would like to match all url's find in a text.
with preg_replace().
Can anyone give me the perfect pattern to math them?
Thanks
Solved: Regular expression for url
Solved: Regular expression for url
Last edited by mister_v on Mon Nov 12, 2012 8:26 pm, edited 1 time in total.
Re: Regular expression for url
I find the following pattern works well for me
"@((https?://|ftp://)([-\w\.]+)+(:\d+)?(/([\w/_\.\-\+\~\=\:]*(\?\S+)?)?)?)@"
Code: Select all
$pattern=array("@((https?://|ftp://)([-\w\.]+)+(:\d+)?(/([\w/_\.\-\+\~\=\:]*(\?\S+)?)?)?)@");
$replace=array("[Somtehing]\\1");
$str=preg_replace($pattern,$replace,$string);
Re: Regular expression for url
On this site you get a good overview of several patterns,
with there pro's and con's:
http://mathiasbynens.be/demo/url-regex
with there pro's and con's:
http://mathiasbynens.be/demo/url-regex
Re: Solved: Regular expression for url
Thanks, this helps me a lot.