I just really started learning how to use regex’s and i am trying to create one to match urls. So far i have:
(http://|https://|www|\w)+\.[\w]{2,4}[^\s]+
can anyone give me some feedback or advice on how this looks, or maybe point me in a better
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
the regex you wrote is a good start, the true power of regex is that it can be very… well… powerful 🙂
there are a lot of differences in the structure of URL that are still considered ok.
consult a Regex Reference to learn more and understand the meaning of all the characters.
and you can check for what the community generates by going to a site like this one
this may be overly complex for what you need but this is a well written regex for URLmatching:
^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$