Parsing URI's using boost regex

I'm trying to write a parser for URIs. I tried the grammar straight from RFC 2396 boost::regex parser("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?", boost::regex::perl|boost::regex::icase); This does not work since it I get an exception due to invalid regular expression. I found another regular expression, which does not throw an exception but does not give me the parts of the URI using boost::match_result boost::regex parser("(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_ !~*'()%]+)?/{0,1}([0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@ &=+$\\.\\-_!~*'()%]+)?", boost::regex::perl|boost::regex::icase); What am I doing wrong here? Reena

On Mon, Jun 2, 2008 at 11:50 AM, Reena Dass
I'm trying to write a parser for URIs. I tried the grammar straight from RFC 2396
boost::regex parser("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?",
boost::regex::perl|boost::regex::icase);
This does not work since it I get an exception due to invalid regular expression.
What am I doing wrong here?
The \? should be \\?, that could be why. -- Cory Nelson
participants (2)
-
Cory Nelson
-
Reena Dass