0

I need to search a string with whitespace using Boost:regex search, but it never matches.

I need to get the username from the work mail (second match in the input below), but the order can change, so I need to scan the whole string.

Input:

homemail: mail:username@mail.com workmail: mail:username@mail.com

Regex:

workmail: mail:\s*([^@>;]*)

In pcre it works correctly: http://regex101.com/r/uD4pH7/1

In Boost, I've tried a lot of ways like:

workmail: mail:\s*([^@>;]*)

workmail:\\smail:\s*([^@>;]*)

workmail:\\x20mail:\s*([^@>;]*)

\\Qworkmail: mail:\\E\s*([^@>;]*)

workmail:[[:space:]]mail:\s*([^@>;]*)

workmail:[[:s:]]mail:\s*([^@>;]*)

My boost lib version is 1.42.0 installed via apt in Debian 6 system. I'm using the boost::regex_search function.

  • So where is the issue? – Braj Aug 13 '14 at 18:33
  • Work in boost 1.54, probably a bug already fixed. Update boost. Tested the first one you try. – NetVipeC Aug 13 '14 at 18:56
  • The issue is that in boost the regex never matches because the whitespace. – Marcio Golf Aug 13 '14 at 19:30
  • Upgraded to Boost 1.56 and the result is the same, it doesn't match anything. @NetVipeC you tested this one **workmail: mail:\s*([^@>;]*)** and it worked ? – Marcio Golf Aug 14 '14 at 18:52
  • @NetVipeC can you please send me the example code that you tested ? – Marcio Golf Aug 14 '14 at 18:58
  • Sorry for the formatting: `#include #include int main() { std::string s = "homemail: mail:username@mail.com workmail: mail:username@mail.com"; boost::smatch m; if (boost::regex_search(s, m, boost::regex("workmail: mail:\s*([^@>;]*)"), boost::match_default | boost::match_partial)) { std::cout << "** Match found **\n Sub-Expressions:\n"; for (unsigned i = 0; i < m.size(); ++i) std::cout << " $" << i << " = \"" << m[i] << "\"\n"; } return 0; }` – NetVipeC Aug 14 '14 at 20:14
  • Thank you @NetVipeC. The upgrade to the new lib version really worked, and all of the regex that I proposed in the main post works. Thank you for your attention. +1 for you! – Marcio Golf Aug 22 '14 at 19:08

0 Answers0