$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: John Maddock (john_at_[hidden])
Date: 2004-12-14 07:58:43
> i try to use the regex library for binary data.
> I tried this code:
>
>      string h("\x81\x05\x00\x48");
>      regex e2("\x81\x05\x00(.)");
>      smatch m;
>      if (regex_match(h, m, e2))
>      {
>            cout << "0. matched=" << (m[0].matched?"true":"false") << endl;
>            cout << "0. match length=" << m[0].str().size() << endl;
>            cout << "0. match character=" << m[0].str() << endl;
>            cout << "1. matched=" << (m[1].matched?"true":"false") << endl;
>            cout << "1. match length=" << m[1].str().size() << endl;
>            cout << "1. match character=" << m[1].str() << endl;
>      }
The thing is if you pass a const char* to either basic_string or 
boost::regex then it will assume that the string is null-terminated, which 
as you have found does the wrong thing in this case.  In both cases use the 
constructor that takes a string length as well as a pointer:
      string h("\x81\x05\x00\x48", 4);
      regex e2("\x81\x05\x00(.)", 7, regex::perl);
Hope this helps,
John.