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

前端 未结 4 580
面向向阳花
面向向阳花 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:20

    According to the POSIX regular expression spec:

    An ordinary character is any character in the supported character set, except for the ERE special characters listed in ERE Special Characters. The interpretation of an ordinary character preceded by a backslash ( '\' ) is undefined.

    So the only characters that can legally follow a \ are:

    \^    \.    \[    \$    \(    \)    \|
    \*    \+    \?    \{    \\
    

    all of which match the escaped character literally. Trying to use any of of the other PCRE extensions may not work.

提交回复
热议问题