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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted June 11, 2012 Author Share Posted June 11, 2012 looking for a regex Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.