0

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):

  • www.example.com/user/login
  • www.example.com
  • www.exmaple.co.xx
  • www.example.com/user?id=234&name=fname

in case if the URL contains only,

  • www.example(without the domain - .com OR .co.xx)
  • example.com (without "www")

I should throw an error to the user.

any help would be highly appreciated...

Thanks Raj

1
  • Are you only checking one domain? In you example, it would be "example". Or do you want the regex to work with any domain? Commented May 16, 2012 at 5:03

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.