regex - Regular expression '<>' validation -


i'm working on building regular expression accept url's , hostnames.

so following should accepted:

google google.com www.google.com http://google.com http://www.google.com 

however should not accepted is:

<xml> <html> 

the expression i've got far is:

([a-za-z0-9])|((http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?) 

however part of expression: ([a-za-z0-9])
matches on <xml> , <html>

anyone suggestions i'm missing here?

you'll need add beginning (^) , end ($) anchors expression ensure pattern specified allowed:

^([a-za-z0-9]+)|((https?://)?([\w-]+\.)+[\w-]+(/[-\w ;,./?%&=]*)?)$ 

Comments