linux c 正则表达式

#include <stdio.h>
#include <regex.h>
#include <mhash.h>

int main() {
    regex_t rgx;
    char *pattern = "^[[:alnum:]]*$";
    char *str = "shabi";
    if (regcomp(&rgx, pattern, REG_EXTENDED | REG_NOSUB) != 0) {
        perror("Invalid regex pattern");
        regfree(&rgx);
        exit(EXIT_FAILURE);
    }

    if (regexec(&rgx, str, 0, NULL, 0) == 0) {
        printf("Match success\n");
    } else {
        printf("Match failed\n");
    }

    regfree(&rgx);

    return 0;
}

 

posted @ 2018-11-06 09:45  SKY_VIEW  阅读(815)  评论(0编辑  收藏  举报