Hi All, Thanks in advance. [((http)|(https))://][www.]domainname.((com)|(gov))[/dir or page name]I am looking for a regex for the above URL format. Could anyone help me please?Thanks!Jenni
A formal answer to your request is something like ^(https?:\/\/)?(www\.)?.+?\.(com|gov)(\/.*)?Please note however that "httkaka:/foo.gov" will match perfectly, after all who's to say that "httkaka:/foo"is not a valid "domainname" in your terminology?So, what are you trying to accomplish? Note that formal URL Syntax validation is surprisingly hard to do in a singleregex. If that's what you are trying to do perhaps little script may serve you better
maybe ^(https?:\/\/)?(www\.)?.+?\.(com\/|gov\/)(\/.*)?
That will work but it is a bit too restrictive. It'll require slash at the end even if there is no path. Following may be somewhat better:^(https?:\/\/)?(www\.)?.+?\.(com|gov)($|\/.*)
... =~ m{^(https?://)?[^/]+\.(com|gov)(|/.*)$};
... =~ m{^(?:https?://)?[^/]+\.(?:com|gov)(|/.*)$};
Here is the code, which we feel was more apt to our req. for the URL validation.validation-regex="^(((http)|(https))(:\/\/))?(www\.)?[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]+\.((com)|(gov))(((\/)|(\\))($|[a-zA-Z0-9\.\\\+]+))*$"/>/>
Is there a question somewhere here? If not, please note that your regex will "fail" some syntactically correct entries like www.yahoo.com/hi-jenny and accept some syntactically wrong ones: www.yahoo.com/hi+jenny.Have you thought about a port that differs from 80? ftp/file/mail protocols? CGI Parameters? Document Anchors?Permutations of all that? I once did a regex few hundred symbols long for that - it still hadplenty of holes in it
...Ghoti,Thanks for the idea. Your regex allows the URL of type,httpsss://www.yahoo.com/a.htm which is not a valid URLThanks!Jenni