0

Problem: I need a Regex which would check a given author URL is valid or not.

Requirement : Author URL is basically a URL from social networking sites/blogs etc having author id (profile id)

For eg .

www.facebook.com/RyanMathews 
www.mouthshut.com/zobo.786

The regex as per my understanding would have to accept any string(combination of any characters ) after the sites complete address is followed by a " / " .

Tried Using this regex but doesnt support author ids

var urlregex = /^((https?:\/\/)?((([a-z\d])+(\-)?([a-z\d])+)+)(\.([a-z\d])+(\-)?([az\d])+)?)(\.[a-z]{2,4}?){1,2}$/i;

PS : Please explain the Regex & Logic too :D

Toto
  • 89,455
  • 62
  • 89
  • 125
Zohaib
  • 417
  • 9
  • 24
  • That's contradictory. If the regex accepts any string after the "sites complete address", it can't check if it is a valid author URL. – Leif Mar 16 '12 at 07:02
  • possible duplicate of [Getting parts of a URL (Regex)](http://stackoverflow.com/questions/27745/getting-parts-of-a-url-regex) – Sudhir Jonathan Mar 16 '12 at 07:10
  • there are many library functions that are 1) unicode capable 2) can trully verify that site is accessible by downloading html or header 3) work in your favourite language. Tell us programming language or simply **UTFG**. You may have seen it, you type into this little box on google.com something like "programming language link check library" and you press I'm feeling lucky button. Use regular expressions to match strings like 'user not found', not for link checking. – Tomas Pruzina Mar 16 '12 at 07:19

2 Answers2

0

it should Help but I will recommend to do little background reading.

What is the best regular expression to check if a string is a valid URL?

Getting parts of a URL (Regex)

Please spend some time to read these links and understand them, hope this helps, cheers!

Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • Nah ! Its a feature I need to support for my product. – Zohaib Mar 16 '12 at 07:09
  • hey, saweet, just asked because it looked like a homework question man, but the above should help you, rest you can get the idea and implement in the language you want. – Tats_innit Mar 16 '12 at 07:15
0
^(http:\/\/){0,1}(www.[^\W]+.com)(\/[^\W]+)+  

maybe this would work

Oleks
  • 31,955
  • 11
  • 77
  • 132
erogol
  • 13,156
  • 33
  • 101
  • 155