M
M
Maxim Barulin2014-05-20 16:43:41
Regular Expressions
Maxim Barulin, 2014-05-20 16:43:41

How to compose a regular expression in c++ to recognize a "raw" POST request?

Good day,% habrauser%!
I continue to understand with ++.
The task is to parse a "raw" POST request of the form:

--------------------------a83ff083a93d5629
Content-Disposition: form-data; name="test"

123456
--------------------------a83ff083a93d5629
Content-Disposition: form-data; name="test2"

33333
--------------------------a83ff083a93d5629
Content-Disposition: form-data; name="test3"

777
--------------------------a83ff083a93d5629--

I'm trying to solve it like this (using boost/regex.hpp):
void match_parts_req(string * response)
{
  regex expression("\"([a-zA-Z0-9_]+)\"\r\n\r\n(.*[^\r\n])\r\n");

  sregex_token_iterator iter(response->begin(), response->end(), expression, 0);
    sregex_token_iterator end;

  cout<<"\nstart matches\n";
    for( ; iter != end; ++iter ) {
        cout<<"value of: \n";
    cout<<*iter<<'\n';
    }

  cout<<"end matches\n";
}

But it seems that in C++ regular expressions work somehow "in a special way", since such a regular expression works quite correctly here , but in the program the entire line is displayed starting from "test" and up to the end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Barulin, 2014-05-20
@Slavenin999

solved with the help of a rewritten regular expression

regex expression("\"([^\r\n]+)\"\r\n\r\n([^\r\n]+)\r\n");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question