-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExer17_14.cpp
76 lines (75 loc) · 2.13 KB
/
Exer17_14.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <string>
#include <regex>
using std::cout;
using std::endl;
using std::string;
using std::regex;
using std::smatch;
using std::regex_error;
int main()
{
// [] mismatch
try {
regex r("[[:alnum]+\\.(cpp|cxx|cc)$", regex::icase);
} catch (regex_error e)
{ cout << e.what() << "\ncode: " << e.code() << endl; }
// () mismatch
try {
regex r("[[:alnum]]+\\.cpp|cxx|cc)$", regex::icase);
} catch (regex_error e)
{ cout << e.what() << "\ncode: " << e.code() << endl; }
// {} mismatch
try {
regex r("[[:alnum]]{1-2\\.(cpp|cxx|cc)$", regex::icase);
} catch (regex_error e)
{ cout << e.what() << "\ncode: " << e.code() << endl; }
// repetition character not preceded by a valid RE
try {
regex r("+\\.(cpp|cxx|cc)$", regex::icase);
} catch (regex_error e)
{ cout << e.what() << "\ncode: " << e.code() << endl; }
// invalid range in {}
try {
regex r("[[:alnum]]{a-x}+\\.(cpp|cxx|cc)$", regex::icase);
} catch (regex_error e)
{ cout << e.what() << "\ncode: " << e.code() << endl; }
// invalid character range
try {
regex r("[z-a]+\\.(cpp|cxx|cc)$", regex::icase);
} catch (regex_error e)
{ cout << e.what() << "\ncode: " << e.code() << endl; }
return 0;
}
// ******result of clang++ and g++******
// regex_error
// code: 1
// regex_error
// code: 1
// regex_error
// code: 1
// regex_error
// code: 5
// regex_error
// code: 1
// regex_error
// code: 8
// ******result of cl******
// regex_error(error_ctype): The expression contained an invalid character class
// name.
// code: 1
// regex_error(error_ctype): The expression contained an invalid character class
// name.
// code: 1
// regex_error(error_ctype): The expression contained an invalid character class
// name.
// code: 1
// regex_error(error_badrepeat): One of *?+{ was not preceded by a valid regular
// expression.
// code: 10
// regex_error(error_ctype): The expression contained an invalid character class
// name.
// code: 1
// regex_error(error_range): The expression contained an invalid character range,
// such as [b-a] in most encodings.
// code: 8