I am preparing to my exams and I am stuck at RegEx validation. I would like to validate an entered web-site. I've surfed for a solution here, but have not found any which will fulfill my needs. For example these links should be validated:
- http://www.yahoo.com/cheers/peter.aspx
- http://www.yahoo.com/asd/
- http://www.regularexpressions.com/reference.html
- http://www.gandon.com/
and this should not:
For the moment the closest expression I got is:
http://(www\.)([^\.]+)(\.com)(/([^\.]+)(\.html|\.aspx))?
It can be a little bit dirty, since it is my first deal with regexes
But in regexTester it highlights/accepts (I am using regexpal):
- http://www.yahoo.com from #2 (without /asd/)
- http://www.yahoo.com/cheers/peter/steven/mar s.aspx from #6 (although there are spaces)
- http://www.radsoftware.com from #5 (but should not accept it at all)
- http://www.gandon.com from #4 (without / , but it is not so critical)
What should be changed in my regex?
P.S. Sorry for such a long story, I am just a beginner.