Hi, I have some trouble with regex. I have a string in this format: =?<encoding>?<Q or B>?<name>?= I want to extract the encoding, Q or B and name! I read the regex documentation and I try this: string mime_decode_field(string field) { boost::regex e("^=?([\x20-\x7E]*)?(Q|B)?([\x20-\x7E]*)?=$",boost::regex::perl|boost::regex::icase); boost::smatch what; if(boost::regex_match(field,what,e)) { //Now I expect <encoding> in what[1], <Q or B> in what[2] and <name> in what[3] } } But it is not as expected. what[2] and what[3] are empty, what[1] contains the whole string. What am I doing wrong? Thanks! nathan
AMDG Nathan Huesken wrote:
I have some trouble with regex. I have a string in this format:
=?<encoding>?<Q or B>?<name>?=
If you want a literal question mark, you need to escape it: "\\?"
I want to extract the encoding, Q or B and name! I read the regex documentation and I try this:
string mime_decode_field(string field) { boost::regex e("^=?([\x20-\x7E]*)?(Q|B)?([\x20-\x7E]*)?=$",boost::regex::perl|boost::regex::icase); boost::smatch what; if(boost::regex_match(field,what,e)) { //Now I expect <encoding> in what[1], <Q or B> in what[2] and <name> in what[3] } }
But it is not as expected. what[2] and what[3] are empty, what[1] contains the whole string.
In Christ, Steven Watanabe
participants (2)
-
Nathan Huesken
-
Steven Watanabe