1. How does the regex_search() function regex_search() ? Suppose there is a string "1 2 3 4". It is necessary to display each digit from the new line.
  2. And yet, there is a line of code regex rx("\\d"); How to redefine rx to another regular expression?

    1 answer 1

    Like that:
    one)

      #include <iostream> #include <string> #include <regex> int main (){ std::string s ("1 2 3 4"); std::smatch m; std::regex e ("\\d"); while (std::regex_search (s,m,e)) { std::cout << m[0] << " "; s = m.suffix().str(); } return 0; } 

    2)

      rx = "\\d+"; 
    • And what does the m.suffix () call do? And how, for example, to search from a certain position in a line? - Bill
    • 2
      The following is a reference to the target sequence. In a nutshell, it returns what comes after the match. If it is not clear in words, in my example you can add std::cout << m.suffix().str(); and see what happens - yrHeTaTeJlb
    • @Bill, in order to search in a substring, you can use the regex_search version with iterators, it will look something like std::regex_search (s.cbegin(), s.cend(), m, e) . Instead of s.cbegin() and s.cend() pass a couple of iterators, between which there is a substring of interest to you - yrHeTaTeJlb