fork download
  1. #include <iostream>
  2. #include <regex>
  3. using namespace std;
  4.  
  5. int main() {
  6. bool caseInsensitive = true;
  7. char pattern[257] = "\\bword\\b";
  8. pattern[14] = '(';
  9. cout << "Pattern: " << pattern << endl;
  10. try
  11. {
  12. cout << "Flags: " << std::regex_constants::ECMAScript << endl;
  13. std::regex re(pattern, std::regex_constants::ECMAScript);
  14. }
  15. catch (std::regex_error &e)
  16. {
  17. cout << "Caught: " << e.what() << endl;
  18. }
  19. try
  20. {
  21. cout << "Flags: " << (std::regex_constants::ECMAScript | (caseInsensitive ? std::regex_constants::icase : 0)) << endl;
  22. std::regex re(pattern, std::regex_constants::ECMAScript | (caseInsensitive ? std::regex_constants::icase : 0));
  23. }
  24. catch (std::regex_error &e)
  25. {
  26. cout << "Caught: " << e.what() << endl;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 3536KB
stdin
Standard input is empty
stdout
Pattern: \bword\b
Flags: 16
Flags: 17
Caught: regex_error