regex - regular expression in c is not working properly -


i want match " 16kqgn579677 pt "

this attempt:

^([a-z0-9]{2}+)([a-z]{4}+)([0-9]{1,6}+)([ ]{0,5}+)([a-z]{1,4}+).*"  

and code:

int main(int argc, char *argv[]){     regex_t str;     int reti;     char msgbuf[100];      /* need match circuit(16kqgn579677 pt) */       reti=regcomp(&str,"^([a-z0-9]{2}+)([a-z]{4}+)([0-9]{1,6}+)([ ]{0,5}+)([a-z]{1,4}+).*",  0);         if( reti )        {        fprintf(stderr, "could not compile regex\n");        exit(1);        }      /* need match circuit(16kqgn579677 pt) */      reti = regexec(&str, "16kqgn579677 pt", 0, null, 0);     if( !reti ){            puts("match");            }     else if( reti == reg_nomatch ){             puts("no match");            }     else   {            regerror(reti, &str, msgbuf, sizeof(msgbuf));            fprintf(stderr, "regex match failed: %s\n", msgbuf);            exit(1);            } regfree(&regex);     return 0; } 

what wrong regex in code?

try instead:

([0-9]{2}\w+\s+[a-z]{1,4})  match regular expression below , capture match backreference number 1 «([0-9]{2}\w+\s+[\w]{2})»    match single character in range between “0” , “9” «[0-9]{2}»       2 times «{2}»    match single character “word character” (letters, digits, , underscores) «\w+»       between 1 , unlimited times, many times possible, giving needed (greedy) «+»    match single character “whitespace character” (spaces, tabs, , line breaks) «\s+»       between 1 , unlimited times, many times possible, giving needed (greedy) «+»    match single character “word character” (letters, digits, , underscores) «[\w]{2}»       2 times «{2}» 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -