正则表达式,要匹配任意数字为什么要 [[:digit:]] 两个括号才行,一个括号就不对
1个回答

具体官网的解释是:These are always used inside square brackets in the form [[:alnum:]] or combined as [[:digit:]a-d]

即:

对于

[:digit:] Only the digits 0 to 9

[:alnum:] Any alphanumeric character 0 to 9 OR A to Z or a to z.

之类的含义,都是必须写成:

[xxx]

即:

[[:digit:]]

[[:alnum:]]

即,语法就是这么定义的.

自己用google搜:

Regular Expressions - A Gentle User Guide and Tutorial

可以找到完整的,详细的解释.

另外,感兴趣的,也可以去看我总结的:

crifan 正则表达式学习心得

(此处不给贴地址,请自己用google搜标题,就可以找到帖子了)