forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex17_15.cpp
38 lines (35 loc) · 1.1 KB
/
ex17_15.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <exception>
#include <iostream>
#include <regex>
#include <string>
using std::regex;
//! @check https://en.wikipedia.org/wiki/I_before_E_except_after_C
int main()
{
try {
regex r("[[:alpha:]]*(cie|[^c]ei)[[:alpha:]]*");
std::string word;
while (std::cout << "Enter a word, or q to quit: ", std::cin >> word) {
if (word == "q") break;
std::smatch result;
if (std::regex_search(word, result, r))
std::cout << "Violate the rule: 'i before e except after c'"
<< std::endl;
else
std::cout << word + " is okay." << std::endl;
}
}
catch (std::regex_error e) {
std::cout << e.what() << "\ncode:" << e.code() << std::endl;
}
}
//! @test
// Enter a word, or q to quit: believe
// believe is okay.
// Enter a word, or q to quit: receive
// receive is okay.
// Enter a word, or q to quit: species
// Violate the rule: 'i before e except after c'
// Enter a word, or q to quit: seize
// Violate the rule: 'i before e except after c'
// Enter a word, or q to quit: q