works:programmer:cpp:regexpr

Пример регулярки на C++

#include <windows.h>
#include <string>
#include <regex>
 
wstring lines = L"Hello world ^RSSI:12\nHello world^RSSI:34And univerce\n^RSSI:22"
wregex expr = wregex(L"RSSI:([0-9]+)"/*, regex_constants::icase*/);
wsmatch match;
wsregex_iterator it;
 
if (regex_search(lines, match, expr)) {
    auto key_bgn = wsregex_iterator(lines.begin(), lines.end(), expr);
    auto key_end = wsregex_iterator();
 
    int found = distance(key_bgn, key_end);
        for (wsregex_iterator it = key_bgn; it != key_end; ++it) {
	    wsmatch match = *it;
            int match_len = match.size();
 
            // match.str() == RSSI:12 
            // match[1].str() == 12
 
            wstring match_str = match[1].str();
 
            MessageBox(0, match_str.c_str(), L"Matched!", MB_ICONINFORMATION);
      }
}
works/programmer/cpp/regexpr.txt · Last modified: 2018/12/15 17:18 (external edit)