#include #include #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"); } }