URI regex validation as per rfc3986
<p>I have been trying to validate a URI entered as per the <a href="http://www.rfc-base.org/txt/rfc-3986.txt" rel="nofollow">RFC 3986</a></p>

<p>This is the one i came up with</p>

<pre><code>(?:[A-Za-z][A-Za-z0-9+.-]*:/{2})?(?:(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})+(?::(?[A-Za-z0-9-._~]|[%][A-Fa-f0-9]{2})+)?@)?(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.){1,126}[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?::[0-9]+)?(?:/(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})*)*(?:\\?(?:[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)(?:&amp;|;[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)*)?
</code></pre>

<p>But somehow this is failing for the following examples </p>

<p>ldap://[2001:db8::7]/c=GB?objectClass?one
 mailto:John.Doe@example.com</p>

<p>from the RFC itself.</p>

<p>Not sure what i am doing wrong</p>

<p>This check is being done when SubjectAltName is given for a certificate and I need to validate it for a well formed URI so that it doesnt fail while generation of certificate. For generation of certificate,Im using bouncycastle</p>