-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExer17_15.cpp
27 lines (27 loc) · 930 Bytes
/
Exer17_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
#include <iostream>
#include <string>
#include <regex>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::regex;
using std::smatch;
int main()
{
// find the characters ei that follow a character other than c
string pattern("[^c]ei");
// we want the whole word in which our pattern appears
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
regex r(pattern); // construct an object to find pattern
smatch results; // define an object to hold the results of a search
// define a string that has text that does and doesn't match pattern
string test_str;
cout << "input a word: " << endl;
while (cin >> test_str) {
// use r to find a match to pattern in test_str
if(regex_search(test_str, results, r)) // if there is a match
cout << "wrong spelling! \"ei\" is reversed." << endl; // print the matching word
}
return 0;
}