fork(8) download
  1. #include <string>
  2. #include <iostream>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::regex r(R"([^\W_]+(?:['_-][^\W_]+)*)");
  8. std::string s = "Hello, world! Aren't you clever? 'Later', she said. Maybe 5 o'clock?' In the year 2017 ... G2g, cya l8r hello_world.h Hermione's time-turner. Good mor~+%g. Hi' Testing_ Bye- The kids' toys";
  9. for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
  10. i != std::sregex_iterator();
  11. ++i)
  12. {
  13. std::smatch m = *i;
  14. std::cout << m.str() << '\n';
  15. }
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 15344KB
stdin
Standard input is empty
stdout
Hello
world
Aren't
you
clever
Later
she
said
Maybe
5
o'clock
In
the
year
2017
G2g
cya
l8r
hello_world
h
Hermione's
time-turner
Good
mor
g
Hi
Testing
Bye
The
kids
toys