1

([\w-]+.)+[\w-]+(/[\w- ./?%&=]*)? I am using the above expression for URL validation. But the problem is when I give only 'www.yahoo' and press the save button I didn't get any error message. Please offer a solution.

Thank you

1

1 Answer 1

3

Well, I guess that post relates more to python. You might find something similar in ASP.NET as well.

But if you want to parse it yourself, you should refer to the RFC 2396 (URI Generic Syntax), which provides the regex and breaks it into components in Appendix B:

  ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
   12            3  4          5       6  7        8 9

The numbers in the second line above are only to assist readability; they indicate the reference points for each subexpression (i.e., each paired parenthesis). We refer to the value matched for subexpression as $. For example, matching the above expression to

  http://www.ics.uci.edu/pub/ietf/uri/#Related

results in the following subexpression matches:

  $1 = http:
  $2 = http
  $3 = //www.ics.uci.edu
  $4 = www.ics.uci.edu
  $5 = /pub/ietf/uri/
  $6 = <undefined>
  $7 = <undefined>
  $8 = #Related
  $9 = Related

where indicates that the component is not present, as is the case for the query component in the above example. Therefore, we can determine the value of the four components and fragment as

  scheme    = $2
  authority = $4
  path      = $5
  query     = $7
  fragment  = $9

and, going in the opposite direction, we can recreate a URI reference from its components using the algorithm in step 7 of Section 5.2.

EDIT:

After a bit of Googling, I found this in ASP.NET: System.Uri, e.g.:

Uri uri = new Uri("http://www.ics.uci.edu/pub/ietf/uri/#Related");
Console.WriteLine(uri.AbsoluteUri);
Console.WriteLine(uri.Host);
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.