![]() |
|< 1 2 >| | ![]() |
18 Einträge, 2 Seiten |
int regexec(const regex_t *, const char *, size_t, regmatch_t [], int);
1
2
3
4
typedef struct {
regoff_t rm_so; // start of match
regoff_t rm_eo; // end of match
} regmatch_t;
regmatch_t rx_match[100];
1
2
char* found[256+1] = {0};
memcpy(found, &text[rx_match[0].rm_so], &text[rx_match[0].rm_so] - &text[rx_match[0].rm_eo]);
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
#include <stdio.h>
#include <regex.h>
#define BUFSIZE 1000
#define NMATCH 100
int main(void) {
char buf[BUFSIZE];
char found[BUFSIZE];
regex_t regexp;
regmatch_t rx_match[NMATCH];
char *str = "[0-9]+";
if (regcomp(®exp, str, 0)!=0) {
return 1;
}
for(;;) {
printf("> "); fflush(stdout);
if ((fgets(buf, BUFSIZE, stdin))==0)
return 0;
if ((regexec(®exp, buf, NMATCH, rx_match, 0))==0) {
printf("Match!!!\n");
memset(found,'0',BUFSIZE*sizeof(char));
memcpy(found, &buf[rx_match[0].rm_so], &buf[rx_match[0].rm_so] - &buf[rx_match[0].rm_eo]);
printf("gefunden: %s\n",found);
}
else
printf("Input doesn't match.\n");
}
}
![]() |
|< 1 2 >| | ![]() |
18 Einträge, 2 Seiten |