dezkit Posted May 22, 2010 Share Posted May 22, 2010 Hey guys I'm trying to do so that it checks if a string has something like http://steamcommunity.com/id/XXXXXXX http://steamcommunity.com/profiles/YYYYYYYYYY where X can equal numbers and letters and where Y can equal a numbers I currently have if(preg_match("/^http://steamcommunity.com/id/[a-zA-Z0-9]/",$str)){ echo "match found 3"; } But it doesn't work gives me error Warning: preg_match() [function.preg-match]: Unknown modifier '/' in C:\xampp\htdocs\steamid.php on line 13 Link to comment https://forums.phpfreaks.com/topic/202602-need-a-little-help/ Share on other sites More sharing options...
cags Posted May 23, 2010 Share Posted May 23, 2010 If you are going to be checking against paths of any kind I would highly recommend not using a forward slash as your delimiter as otherwise you will need to escape every instances of it in your pattern. You also need to escape the . in your pattern. I'd also guess that since you say X can equal 'numbers and letters' i.e. plurals, that you need a quantifier to make the capture group match more than one character. if(preg_match("~^http://steamcommunity\.com/id/[a-zA-Z0-9]+~",$str)){ echo "match found 3"; } Link to comment https://forums.phpfreaks.com/topic/202602-need-a-little-help/#findComment-1062164 Share on other sites More sharing options...
ZachMEdwards Posted May 31, 2010 Share Posted May 31, 2010 if(preg_match('%http://steamcommunity\.com/(?:id|profiles)/\w+%m',$str)){ echo "match found 3"; } That's how I'd do it. Link to comment https://forums.phpfreaks.com/topic/202602-need-a-little-help/#findComment-1065500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.