Antwort: Re: [Boost-users] Using zero characters in regular expessions
Thanks a lot! Works very fine. --- Keno Basedow GEDIS GmbH Sophienblatt 100 D-24114 Kiel Fon: +49-431-60051-24 (-0) Fax: +49-431-60051-11 basedow@gedis-online.de |---------+-----------------------------------> | | "John Maddock" | | | <john@johnmaddock.co.uk>| | | Gesendet von: | | | boost-users-bounces@list| | | s.boost.org | | | | | | | | | 14.12.2004 13:58 | | | Bitte antworten an | | | boost-users | | | | |---------+----------------------------------->
------------------------------------------------------------------------------------------------------------------------------| | | | An: <boost-users@lists.boost.org> | | Kopie: | | Thema: Re: [Boost-users] Using zero characters in regular expessions | ------------------------------------------------------------------------------------------------------------------------------|
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. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (1)
-
Keno.Basedow@gedis.rohde-schwarz.com