-
Notifications
You must be signed in to change notification settings - Fork 33
/
17.15.cpp
32 lines (30 loc) · 843 Bytes
/
17.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
/*
* Exercise 17.15: Write a program using the pattern that finds words that
* violate the "i before e except after c" rule. Have your program prompt the
* user to supply a word and indicate whether the word is okay or not. Test
* your program with words that do and do not violate the rule.
*
* By Faisal Saadatmand
*/
#include <iostream>
#include <string>
#include <regex>
int main()
{
std::string word;
std::string pattern("[^c]ie");
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
std::regex r(pattern, std::regex::icase);
std::smatch result;
std::cout << "RULE: \"i before e, except after c\"\n";
while (true) {
std::cout << "Enter word: ";
if (!(std::cin >> word) || word == "q")
break;
if (std::regex_search(word, result, r))
std::cout << "okay!\n";
else
std::cout << "not okay\n";
}
return 0;
}