Regular expression for checking website url

Posted by Linto davis on Stack Overflow See other posts from Stack Overflow or by Linto davis
Published on 2010-03-22T06:14:42Z Indexed on 2010/03/22 6:21 UTC
Read the original article Hit count: 404

Filed under:
|

I need to check the web address, using regular expression.

if user type url as

  1. www.test.com
  2. http://www.test.com
  3. https://www.test.com

i have a regular expression like

/^(http\:\/\/[a-zA-Z0-9_-]+(?:.[a-zA-Z0-9_-]+)*.[a-zA-Z]{2,4}(?:\/[a-zA-Z0-9_]+)*(?:\/[a-zA-Z0-9_]+.[a-zA-Z]{2,4}(?:\?[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)?)?(?:\&[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)*)$/

but it will only allow the second option only. how can i modify the regular expression so that , it should accept 1st and 3rd option too

© Stack Overflow or respective owner

Related posts about regex

Related posts about php