I'm using a regex to separate the fields of an HTTP request:
GET /index.asp?param1=hello¶m2=128 HTTP/1.1
This way:
smatch m;
try
{
regex re1("(GET|POST) (.+) HTTP");
regex_search(query, m, re1);
}
catch (regex_error e)
{
printf("Regex 1 Error: %d\n", e.code());
}
string method = m[1];
string path = m[2];
try
{
regex re2("/(.+)?\\?(.+)?");
if (regex_search(path, m, re2))
{
document = m[1];
querystring = m[2];
}
}
catch (regex_error e)
{
printf("Regex 2 Error: %d\n", e.code());
}
If I run this code in Windows, it works. Run it in Linux (Ubuntu Server 14.04 with GCC version 4.8.2) and I get the error code 2:
regex_error(error_escape): The expression contained an invalid escaped character, or a trailing escape.
I just don't know where the error is, the expression looks correct to me. Can you suggest a better expression or a different method of splitting that string?
Aucun commentaire:
Enregistrer un commentaire