0

我正在尝试在输入字符串中查找 UUID。我在http://www.peope.net/old/regex.html修改了示例代码并提出了这个:

#include <sys/types.h>
#include <regex.h>
#include <stdio.h>

int main(int argc, char *argv[]){
    regex_t regex;
    int reti;
    char msgbuf[100];

/* Compile regular expression */
    reti = regcomp(&regex, "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", 0);
    if( reti ){ fprintf(stderr, "Could not compile regex\n"); exit(1); }

/* Execute regular expression */
    reti = regexec(&regex, "'id':'0677233b-65e5-4d62-a202-2120536210d6'", 0, NULL, 0);
    if( !reti ){
            puts("Match");
    }
    else if( reti == REG_NOMATCH ){
            puts("No match");
    }
    else{
            regerror(reti, &regex, msgbuf, sizeof(msgbuf));
            fprintf(stderr, "Regex match failed: %s\n", msgbuf);
            exit(1);
    }

/* Free compiled regular expression if you want to use the regex_t again */
    regfree(&regex);

    return 0;
}

但是,它不匹配。有什么建议吗?

4

1 回答 1

1

{N} is an extended regexp feature. Pass the REG_EXTENDED flag to regcomp.

于 2013-11-06T18:18:26.887 回答