---------------
void use()
{
    ifstream in("plik.txt");  // plik wejciowy
    if (!in) cerr << "brak pliku\n";

    regex pat {R"(\w{2}\s*\d{5}(-\d{4})?)"}; // wzorzec kodu pocztowego w formacie stosowanym w USA

    int lineno = 0;
    for (string line; getline(in,line); ) {
        ++lineno;
        smatch matches; // tu s zapisywane znalezione acuchy
        if (regex_search(line, matches, pat)) {
            cout << lineno << ": " << matches[0] << '\n'; // kompletne dopasowanie
            if (1<matches.size() && matches[1].matched)
                cout  << "\t: " << matches[1] << '\n'; // poddopasowanie
        }
    }
}
---------------
regex pat {"\\w{2}\\s*\\d{5}(-\\d{4})?"}; // wzorzec kodu pocztowego w formacie stosowanym w USA

---------------
^A*B+C?$
---------------
AAAAAAAAAAAABBBBBBBBBC
BC
B
---------------
AAAAA   // brak B
 AAAABC // spacja na pocztku
AABBCC  // za duo C
---------------
A{3}B{2,4}C*
---------------
AAABBC
AAABBB
---------------
AABBC       // za mao A
AAABC       // za mao B
AAABBBBBCCC // za duo B
---------------
ababab
---------------
[:alpha:][:alnum:]*             // niepoprawny: znaki ze zbioru :alpha i :alnum
[[:alpha:]][[:alnum:]]*         // niepoprawny: nie dopuszcza uycia znaku podkrelenia ('_' nie jest 
                                // znakiem alfabetu)
([[:alpha:]]|_)[[:alnum:]]*     // niepoprawny: znak podkrelenia nie naley do znakw alfanumerycznych
([[:alpha:]]|_)([[:alnum:]]|_)* // OK, ale niezgrabne
[[:alpha:]_][[:alnum:]_]*       // OK: dodaje znak podkrelenia do klas znakw
[_[:alpha:]][_[:alnum:]]*       // OK
[_[:alpha:]]\w*                 // \w jest rwnoznaczne z [_[:alnum:]]
---------------
bool is_identifier(const string& s)
{
    regex pat {"[_[:alpha:]]\\w*"};
    return regex_match(s,pat);
}

---------------
bool is_identifier(const string& s)
{
    regex pat {R"([_[:alpha:]]\w*)"};
    return regex_match(s,pat);
}
---------------
Ax*           // A, Ax, Axxxx
Ax+           // Ax, Axxx nie A
\d-?\d        // 1-2, 12 nie 1--2
\w{2}-\d{4,5} // Ab-1234, XX-54321, 22-5432 cyfry s w \w
(\d*:)?(\d+)  // 12:3, 1:23, 123, :123 nie 123:
(bs|BS)       // bs, BS nie bS
[aeiouy]      // a, o, u, angielskie samogoski, nie x
[^aeiouy]     // x, k, nie angielska samogoska, nie e
[a^eiouy]     // a, ^, o, u, angielska samogoska lub ^
---------------
(\s|:|,)*(\d*) // odstpy, dwukropki i/lub przecinki, po ktrych znajduje si liczba
---------------
(?\s|:|,)*(\d*) // odstpy, dwukropki i/lub przecinki, po ktrych znajduje si liczba

---------------
Zawsze patrz <b>optymistycznie</b> na <b>ycie</b>.
---------------
template<typename C, typename Tr = regex_traits<C>>
class basic_regex {
public:
    using value_type = C;
    using traits_type = Tr;
    using string_type = typename Tr::string_type;
    using flag_type = regex_constants::syntax_option_type;
    using locale_type = typename Tr::locale_type;
    ~basic_reg ex(); // niewirtualny; klasa basic_regex nie powinna by uywana jako baza
    //...
};
---------------
using regex = basic_regex<char>;
---------------
regex pat1 {R"(\w+\d*)"}; // brak moliwoci wywietlenia wzorca znajdujcego si w pat1
string s {R"(\w+\d*)"};
reg ex pat2 {s};
cout << s << '\n';        // wzorzec uyty w pat2
---------------
template<typename Bi>
class sub_match : public pair<Bi,Bi> {
public:
    using value_type = typename iterator_traits<Bi>::value_type;
    using difference_type = typename iterator_traits<Bi>::difference_type;
    using iterator = Bi;
    using string_type = basic_string<value_type>;
    bool matched; // prawda, jeli *this zawiera dopasowanie
    //...
};

---------------
regex pat ("<(.*?)>(.*?)</(.*?)>");
string s = "Zawsze patrz <b> optymistycznie </b> na <b> mier </b>";
if (regex_search(s,m,pat))
if (m[1]==m[3]) cout << "match\n";
---------------
template<typename Bi, typename A = allocator<sub_match<Bi>>>
class match_results {
public:
    using value_type = sub_match<Bi>;
    using const_reference = const value_type&;
    using reference = const_reference;
    using const_iterator = /* zalene od implementacji */;
    using iterator = const_iterator;
    using difference_type = typename iterator_traits<Bi>::difference_type;
    using size_type = typename allocator_traits<A>::size_type;
    using allocator_type = A;
    using char_type = typename iterator_traits<Bi>::value_type;
    using string_type = basic_string<char_type>;
    ~match_results(); // niewirtualny
    //...
};
---------------
using cmatch = match_results<const char*>;               // acuch w stylu C
using wcmatch = match_results<const wchar_t*>;           // szeroki acuch w stylu C
using smatch = match_results<string::const_iterator>;    // string
using wsmatch = match_results<wstring::const_iterator>;  // wstring
---------------
void test()
{
    regex pat ("(AAAA)(BBB)?");
    string s = "AAAA";
    smatch m;
    regex_search(s,m,pat);

    cout << boolalpha;
    cout << m[0].matched << '\n'; // prawda: znaleziono dopasowanie
    cout << m[1].matched << '\n'; // prawda: byo pierwsze poddopasowanie
    cout << m[2].matched << '\n'; // fasz: brak drugiego poddopasowania
    cout << m[3].matched << '\n'; // fasz: nie mogo by trzeciego dopasowania 
}
---------------
Klasa      Chopcw    Dziewczt   Suma
1a         12          15          27
1b         16          14          30
Suma       28          29          57
---------------
int main()
{
    ifstream in("table.txt"); // plik wejciowy
    if (!in) cerr << "brak pliku\n";

    string line; // bufor wejciowy
    int lineno = 0;

    regex header {R"(^[\w ]+(\t[\w ]+)*$)"}; // sowa rozdzielane tabulatorami
    regex row {R"(^([\w ]+)(\t\d+)(\t\d+)(\t\d+)$)"}; // etykieta, po ktrej znajduj si trzy 
                                                      // oddzielane tabulatorami liczby

    if (getline(in,line)) { // sprawdza i odrzuca wiersz nagwka
        smatch matches;
        if (!regex_match(line,matches,header))
            cerr << "brak nagwka\n";
    }

    int boys = 0; // sumy biece
    int girls = 0;

    while (getline(in,line)) {
        ++lineno;
        smatch matches; // poddopasowania

        if (!regex_match(line,matches,row))
            cerr << "bdny wiersz: " << lineno << '\n';

        int curr_boy = stoi(matches[2]);  // opis stoi() znajduje si w 36.3.5
        int curr_girl = stoi(matches[3]);
        int curr_total = stoi(matches[4]);
        if (curr_boy+curr_girl != curr_total) cerr << "niepoprawna suma wierszy\n";

        if (matches[1]=="Suma") { // ostatni wiersz
            if (curr_boy != boys) cerr << "suma chopcw si nie zgadza\n";
            else if (curr_girl != girls) cerr << "suma dziewczt si nie zgadza\n";
            else cout << "w porzdku\n";
            return 0;
        }
        boys += curr_boy;
        girls += curr_girl;
    }

    cerr << "nie znaleziono wiersza sum\n";
    return 1;
}

---------------
regex pat {"[Ss]tro?u?v?p?stra?o?u?p?b?"};

smatch m;
for (string s; cin>>s; )
           if (regex_search(s,m,pat))
                 if (m[0]!="stroustrup" && m[0]!="Stroustrup" )
                        cout << "Znaleziono: " << m[0] << '\n';
---------------
Znaleziono: strupstrup
Znaleziono: Strovstrup
Znaleziono: stroustrub
Znaleziono: Stroustrop

---------------
void test1()
{
    string input {"x 1 y2 22 zaq 34567"};
    regex pat {"(\w+)\s(\d+)"}; // sowo odstp liczba
    string format {"{$1,$2}\n"};

    cout << regex_replace(input,pat,format);
}
---------------
{x,1}
{y2,22}
{zaq,34567}
---------------
cout << regex_replace(input,pat,format,regex_constants::format_no_copy);
---------------
{x,1}
{y2,22}
{zaq,34567}
---------------
void test2()
{
    string input {"x 1 y2 22 zaq 34567"};
    regex pat {"(\w+)\s(\d+)"}; // sowo odstp liczba
    string format {"$2: $1\n"};
    cout << regex_replace(input,pat,format,regex_constants::format_no_copy);
}
---------------
1: x
22: y2
34567: zaq
---------------
template<typename Bi,
         class C = typename iterator_traits<Bi>::value_type ,
         class Tr = typename regex_traits<C>::type>
class regex_iterator {
public:
    using regex_type = basic_regex<C,Tr>;
    using value_type = match_results<Bi>;
    using difference_type = ptrdiff_t;
    using pointer = const value_type*;
    using reference = const value_type&;
    using iterator_category = forward_iterator_tag;
    //...
};
---------------
using cregex_iterator = regex_iterator<const char*>;
using wcregex_iterator = regex_iterator<const wchar_t*>;
using sregex_iterator = regex_iterator<string::const_iterator>;
using wsregex_iterator = regex_iterator<wstring::const_iterator>;
---------------
void test()
{
    string input = "aa as; asd ++e^asdf asdfg";
    regex pat {R"(\s+(\w+))"};
    for (sregex_iterator p(input.begin(),input.end(),pat); p!=sregex_iterator{}; ++p)
        cout << (*p)[1] << '\n';
}
---------------
as
asd
asdfg
---------------
aa
as
asd
e
asdf
asdfg
---------------
template<typename Bi,
    class C = typename iterator_traits<Bi>::value_type ,
    class Tr = typename regex_traits<C>::type>
class regex_token_iterator {
public:
    using regex_type = basic_regex<C,Tr>;
    using value_type = sub_match<Bi>;
    using difference_type = ptrdiff_t;
    using pointer = const value_type*;
    using reference = const value_type&;
    using iterator_category = forward_iterator_tag;
    //...
---------------
using cregex_token_iterator = regex_token_iterator<const char*>;
using wcregex_token_iterator = regex_token_iterator<const wchar_t*>;
using sregex_token_iterator = regex_token_iterator<string::const_iterator>;
using wsregex_token_iterator = regex_token_iterator<wstring::const_iterator>;
---------------
void test1()
{
    string input {"aa::bb cc::dd ee::ff"};
    regex pat {R"((\w+)([[:punct:]]+)(\w+)\s*)"};
    sregex_token_iterator end {};
    for (sregex_token_iterator p{input.begin(),input.end(),pat,{1,3}}; p!=end; ++p)
        cout <<*p << '\n';
}
---------------
aa
bb
cc
dd
ee
ff
---------------
void test2()
{
    string s {"1,2 , 3 ,4,5, 6 7"}; // dane wejciowe
    regex pat {R"(\s*,\s*)"};       // uycie przecinka jako separatora tokenw
    copy(sregex_token_iterator{s.begin(),s.end(),pat,-1)},
    sregex_token_iterator{},
        ostream_iterator<string>{cout,"\n"});
}
---------------
1
2
3
4
5
67
---------------
void test3()
{
    sregex_token_iterator end{};
    for (sregex_token_iterator p {s.begin(),s.end(),pat,-1}; p!=end; ++p)
        cout << *p << '\n';
}
---------------
template<typename C>
struct regex_traits {
public:
    using char_type = C;
    using string_type = basic_string<char_type>;
    using locale_type = locale;
    using char_class_type = /* zdefiniowany w implementacji typ maski bitowej */;
    //...
};