Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <exception>
  3. #include <regex>
  4. #include <string>
  5.  
  6. int main()
  7. {
  8.     try {
  9.         std::regex r("[[:alpha:]]*(cie|[^c]ei)[[:alpha:]]*");
  10.         std::string word;
  11.         while(std::cout << "Enter a word or 'q' to quit: ", std::cin >> word)
  12.         {
  13.             if(word == "q") break;
  14.  
  15.             std::smatch result;
  16.  
  17.             if(std::regex_search(word, result, r))
  18.             {
  19.                 std::cout << "Violate the reule!" << std::endl;
  20.             } else {
  21.                 std::cout << word << " is ok!" << std::endl;
  22.             }
  23.         }
  24.     }
  25.     catch (std::regex_error e)
  26.     {
  27.         std::cout << e.what() << std::endl << "Code: " << e.code() << std::endl;
  28.     }
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement