1 | #include <stdio.h>
|
---|
2 |
|
---|
3 | #include <boost/regex.hpp>
|
---|
4 |
|
---|
5 | using namespace boost;
|
---|
6 |
|
---|
7 | int main()
|
---|
8 | {
|
---|
9 | char exp0[] = "=a-c=";
|
---|
10 | char exp1[] = "[^a-c]";
|
---|
11 | char exp2[] = "=[a-c]=";
|
---|
12 | char *exps[] = {exp0,exp1,exp2};
|
---|
13 | regex example0 ("=a-c="); //the regex of the example
|
---|
14 | regex example1 ("=[a-c]="); //the regex of the example
|
---|
15 | regex correct ("[^a-c]"); //the correct regex
|
---|
16 | regex expressions[] = {example0,correct,example1};
|
---|
17 |
|
---|
18 | char p0[] = "=a-c=";
|
---|
19 | char p1[] = "d";
|
---|
20 | char p2[] = "a";
|
---|
21 | char p3[] = "=a=";
|
---|
22 | char *phrases[] = {p0,p1,p2,p3};
|
---|
23 |
|
---|
24 |
|
---|
25 | unsigned int i,j;
|
---|
26 | for(i=0 ; i<3 ; i++)
|
---|
27 | {
|
---|
28 | for(j=0 ; j<4 ; j++)
|
---|
29 | {
|
---|
30 | match_results<const char*> what;
|
---|
31 | regex_match(phrases[j],what,expressions[i]);
|
---|
32 | if(what[0].matched)
|
---|
33 | printf("%s matched %s\n",exps[i],what.str(0).c_str());
|
---|
34 | else
|
---|
35 | printf("%s did not match %s\n",exps[i],phrases[j]);
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | return 0;
|
---|
40 |
|
---|
41 | }
|
---|