-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo.c
33 lines (28 loc) · 1.01 KB
/
demo.c
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
#include "regexp9.h"
#include <stdio.h>
int main() {
const char* pattern = "(?i)(hell.)([ \\t]\\w.rld)+";
const char* input = "Hell😀 W😀rld\tworld ωXrld\nHELL@ W8rld\twørld Ωårld";
/*
const char * pattern = "(5[1-5]\\d\\d)[\\- ]?(\\d\\d\\d\\d)[\\- ]?"
"(\\d\\d\\d\\d)[\\- ]?(\\d\\d\\d\\d)";
const char * input = "5111 2222-3333-4444";
const char* pattern = "([[:lower:]]+[., ]*)+";
const char* input = "Sáhtán borrat lása, dat ii leat bávččas";
*/
enum {N=5};
cregmatch_t m[N] = {0};
int n;
cregex_t rx;
int ret = cregex_compile(&rx, pattern, 0);
while ((n = cregex_find(&rx, input, N, m, creg_fullmatch|creg_next)) > 0)
{
printf("`%s` => matched `%s`", input, pattern);
//for (int i=0; i<n; ++i)
// printf(" (%d, %d)", (int)(m[i].str - input), (int)m[i].len);
puts("");
for (int i=0; i<n; ++i)
printf("%d: (%.*s)\n", i, (int)m[i].len, m[i].str);
}
cregex_free(&rx);
}