Link to home
Start Free TrialLog in
Avatar of lenamtl
lenamtlFlag for Canada

asked on

Need some help with regex

Hi,

I have this php regex to validate url, this is working fine but it's allows
these formats that I want to prevent ww.test.org and w.test.org

So is this possible to catch these cases  with or without http https, without blocking others cases?
This should accept with or without http, https, with or without www
Some accepted formats
www.code.org
http://code.longtd
https://code.uk.co
code.com
http://code.com

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

Open in new window


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rgonzo1971
Rgonzo1971

You could even use

(?!w+\.)
since you would  only 3 w and not any other number of w(1,2,4,...)
Avatar of lenamtl

ASKER

Thanks