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}拡張正規表現機能です。REG_EXTENDEDにフラグを渡しregcompます。

于 2013-11-06T18:18:26.887 に答える