[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/regex [Back]  [Original]

( C++11) cppreference.com
cppreference.com

( C++11)

cppreference.com
< cpp
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 

, , -, . :

.


( ) []
(C++11)
,
( ) []
,
( ) []

, regex, .


( ) []

( ) []

( ) []

, .


( ) []

( ) []

, .

,
() []

.

,
( ) []

std::regex_constants
,
( ) []
,
( ) []

( ) []

#include <iostream>
#include <iterator>
#include <string>
#include <regex>

int main()
{
    std::string s = " ,   , : "
        "\" ,     .\" "
        "     .";

    std::regex self_regex(" ",
            std::regex_constants::ECMAScript | std::regex_constants::icase);
    if (std::regex_search(s, self_regex)) {
        std::cout << "   ' '\n";
    }

    std::regex word_regex("(\\w+)");
    auto words_begin = 
        std::sregex_iterator(s.begin(), s.end(), word_regex);
    auto words_end = std::sregex_iterator();

    std::cout << " "
              << std::distance(words_begin, words_end)
              << " \n";

    const int N = 6;
    std::cout << "  " << N << " :\n";
    for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
        std::smatch match = *i;
        std::string match_str = match.str();
        if (match_str.size() > N) {
            std::cout << "  " << match_str << '\n';
        }
    }

    std::regex long_word_regex("(\\w{7,})");
    std::string new_s = std::regex_replace(s, long_word_regex, "[$&]");
    std::cout << new_s << '\n';
}

:

   ' '
 19 
  6 :
  
  
  
  
  
  
  
[] , []  [], : 
" ,   [] [] []."
     [].

Web Proxy Viewer  |  New URL  |  Original Page