ballhogjoni Posted June 11, 2012 Share Posted June 11, 2012 so im trying to match the path of a url. example: /p/alsdjjlse My regex so far: ^\/([a-z])(?:\/(\w+))?$ this will match the following: /p/alsdjjlse /p but it won't match: /p/ I can't figure this out, any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/264002-trying-to-match-a-url/ Share on other sites More sharing options...
Andy-H Posted June 11, 2012 Share Posted June 11, 2012 Better off with filter_var than regex: $uris = array( 'www.google.com', 'http://www.google.com', 'google.com', 'rfdgedg' ); foreach($uris as $uri) var_dump(filter_var($uri, FILTER_VALIDATE_URL)); boolean false string 'http://www.google.com' (length=21) boolean false boolean false Link to comment https://forums.phpfreaks.com/topic/264002-trying-to-match-a-url/#findComment-1352960 Share on other sites More sharing options...
ballhogjoni Posted June 11, 2012 Author Share Posted June 11, 2012 looking for a regex Link to comment https://forums.phpfreaks.com/topic/264002-trying-to-match-a-url/#findComment-1352961 Share on other sites More sharing options...
Andy-H Posted June 11, 2012 Share Posted June 11, 2012 Take it it's homework then? How to find a URL validation regular expression Link to comment https://forums.phpfreaks.com/topic/264002-trying-to-match-a-url/#findComment-1352965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.