When using regex in C, \d does not work but [0-9] does

前端 未结 4 575
面向向阳花
面向向阳花 2020-12-11 08:07

I do not understand why the regex pattern containing the \\d character class does not work but [0-9] does. Character classes, such as \\s

4条回答
  •  执笔经年
    2020-12-11 08:21

    Trying either pattern in a strictly POSIX environment will likely end up having no matches; if you want to make the pattern truly POSIX compatible use all bracket expressions:

    const char *rstr = "^[[:digit:]]+[[:space:]]+[[:alpha:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:alpha:]]+$";
    

    ↳ POSIX Character_classes

提交回复
热议问题