Raj
Raj

Reputation: 91

regex for validate URL without http/https

All,

I am new to REGEX world...

I know that there are lot of regex avail for validating the common URL with http in it.

But I am looking for a regex to validate the URL in the following formats(without HTTP/HTTPS):

in case if the URL contains only,

I should throw an error to the user.

any help would be highly appreciated...

Thanks Raj

Upvotes: 0

Views: 1797

Answers (1)

Bohemian
Bohemian

Reputation: 425278

This regex will pass your first set, but not match the second set:

^www\.example\.(com|co.xx)(/.*)?$

In English, this regex requires:

  • starts with www.example.
  • followed by either com or co.xx
  • optionally followed by / then anything

You could be more prescriptive about what can follow the optional slash by replacing (/.*) with (/(user|buy|sell)\?.*) etc

Upvotes: 0

Related Questions