0

Below regular expression not working without www

 /((?:https?\:\/\/|www\.)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)/i

I have checked below URLs

http://regexr.com       (working, match)
http://www.regexr.com/  (working, match)
www.regexr.com          (working, match)
regexr.com              (not working, should be match)
abc@gmail.com           (working, not match)

If i used below code

((?:https?\:\/\/|)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)

then it matched email id also

abc@gmail.com           (not working, should not match)
thecodedeveloper.com
  • 3,220
  • 5
  • 36
  • 67

2 Answers2

1

Demo on regexr.com

(https?:\/\/)?\w+(\.\w+)+(\/\w+)*(\/\w+\.\w+)?(\?[\w%&=.]*)*(?=[^\w.?&%=])

try this,

Parth Patel
  • 521
  • 2
  • 12
0

Below regular expression worked fine, more information click here

^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$

Worked because it match below Url's and not email id

http://regexr.com/

http://www.regexr.com/

https://regexr.com

https://www.regexr.com

www.regexr.com

regexr.com

abc@gmail.com (worked, it not match email id)

Demo

thecodedeveloper.com
  • 3,220
  • 5
  • 36
  • 67