Validating a URI according to RFC 3986 using boost::regex

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Validating a URI according to RFC 3986 using boost::regex

Jean-Sebastien Vachon
Hi All,

I'm trying to use the regex library in order to validate a generic
URI according to the regular expression specified in RFC 3986 - Uniform
Resource Identifier (URI): Generic Syntax.

Here is the expression:

      ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?

As far as I know this is a POSIX compliant regex. I'm building my
regex with the following flags:

boost::regex::basic | boost::regex::icase

Here is the complete code:

bool RegExPOSIXValidator::IsValid(const std::string &oName) const
{
/* -------------------------------------------------------------------- */
/*      Build the Regular Expression                                    */
/* -------------------------------------------------------------------- */

   boost::regex re(moRegex, boost::regex::basic | boost::regex::icase);
   return boost::regex_match(oName, re);
}

The function is returning false for the following URI:
http://dimitrov@...:88/index1.html?name=dimitrov#title
Which seem valid to me. Unless there is something I don't see.

I try doubling the \ in front of the ? at the end of the expression
as a solution but it didn't help.

Any idea?

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Validating a URI according to RFC 3986 usingboost::regex

John Maddock
> I'm trying to use the regex library in order to validate a generic
> URI according to the regular expression specified in RFC 3986 -
> Uniform Resource Identifier (URI): Generic Syntax.
>
> Here is the expression:
>
>      ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
>
> As far as I know this is a POSIX compliant regex. I'm building my
> regex with the following flags:
>
> boost::regex::basic | boost::regex::icase

It's *not* a POSIX-basic expression (POSIX basic doesn't support parenthesis
or the + operator).

Use it as a POSIX-extended expression, or actually it'll work as a perl
expression as well (and is likely to be more efficient as well).

John.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users