fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. const std::string text = "This is a test string [more or less] and here is [another].";
  8. const std::regex ws_re(R"(\[([^\]\[]*)\])");
  9. std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, 1),
  10. std::sregex_token_iterator(),
  11. std::ostream_iterator<std::string>(std::cout, "\n"));
  12.  
  13. return 0;
  14. }
  15.  
Success #stdin #stdout 0.01s 5452KB
stdin
Standard input is empty
stdout
more or less
another