Page 1 of 1

including slash inside group

Posted: Sat Sep 03, 2005 9:47 pm
by jaymoore_299
using this pattern
preg_match_all("|http[://]+[A-Za-z0-9_.-]+|", $contents , $matches);
for string
http://some-domain-name.com

gives the result http://some-domain-name.com

however, if I include a slash, whether by itself or escaped
preg_match_all("|http[://]+[A-Za-z0-9_.-/]+|", $contents , $matches);
or
preg_match_all("|http[://]+[A-Za-z0-9_.-\/]+|", $contents , $matches);

I get the result
http://some

How do I include slashes?

Posted: Sat Sep 03, 2005 10:14 pm
by feyd
your regex is still going to match lots of incorrect data. Here's a push in the right direction

Code: Select all

preg_match_all('`https?://[A-z0-9_-][A-z0-9_\./-]+`',$text,$matches);
I can recommend you download and use "Regex Coach"

Posted: Sat Sep 03, 2005 10:22 pm
by neophyte
Thanks for the tip Feyd. Regex Coach is very cool!

http://www.weitz.de/regex-coach/#install