fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10. regex syntax("(a|an|the)\\s+[A-Za-z]+");
  11.  
  12. string text;
  13.  
  14. while (getline(cin, text)) {
  15. sregex_iterator iter(text.begin(), text.end(), syntax);
  16. sregex_iterator end;
  17.  
  18. cout << text << endl;
  19.  
  20. while(iter != end)
  21. {
  22. cout<< "match at: " << iter->position() << " with string: " << iter->str() << endl;
  23. ++iter;
  24. }
  25. cout << endl;
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 3552KB
stdin
It's a book and an antenna, but I prefer the book than this piece of metal.
Man smarter than an animal.
stdout
It's a book and an antenna, but I prefer the book than this piece of metal.
match at: 5 with string: a book
match at: 16 with string: an antenna
match at: 41 with string: the book
match at: 52 with string: an this

Man smarter than an animal.
match at: 1 with string: an smarter
match at: 14 with string: an an