Difference between [0-9], [[:digit:]] and \d
Yes, it is [[:digit:]] ~ [0-9] ~ \d (where ~ means aproximate).
In most programming languages (where it is supported) \d ≡ [[:digit:]] (identical).
The \d is less common than [[:digit:]] (not in POSIX but it is in GNU grep -P).
There are many digits in UNICODE, for example:
123456789 # Hindu-Arabic Arabic numerals٠١٢٣٤٥٦٧٨٩ # ARABIC-INDIC۰۱۲۳۴۵۶۷۸۹ # EXTENDED ARABIC-INDIC/PERSIAN߀߁߂߃߄߅߆߇߈߉ # NKO DIGIT०१२३४५६७८९ # DEVANAGARI
All of which may be included in [[:digit:]] or \d.
Instead, [0-9] is generally only the ASCII digits 0123456789.
There are many languages: Perl, Java, Python, C. In which [[:digit:]] (and \d) calls for an extended meaning. For example, this perl code will match all the digits from above:
$ a='0123456789 ٠١٢٣٤٥٦٧٨٩ ۰۱۲۳۴۵۶۷۸۹ ߀߁߂߃߄߅߆߇߈߉ ०१२३४५६७८९'
$ echo "$a" | perl -C -pe 's/[^\d]//g;' ; echo
0123456789٠١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹߀߁߂߃߄߅߆߇߈߉०१२३४५६७८९
Which is equivalent to select all characters that have the Unicode properties of Numeric and digits:
$ echo "$a" | perl -C -pe 's/[^\p{Nd}]//g;' ; echo
0123456789٠١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹߀߁߂߃߄߅߆߇߈߉०१२३४५६७८९
Which grep could reproduce (the specific version of pcre may have a diferent internal list of numeric code points than Perl):
$ echo "$a" | grep -oP '\p{Nd}+'
0123456789
٠١٢٣٤٥٦٧٨٩
۰۱۲۳۴۵۶۷۸۹
߀߁߂߃߄߅߆߇߈߉
०१२३४५६७८९
Change it to [0-9] to see:
$ echo "$a" | grep -o '[0-9]\+'
0123456789
POSIX
For the specific POSIX BRE or ERE:
The \d is not supported (not in POSIX but is in GNU grep -P). [[:digit:]] is required by POSIX to correspond to the digit character class, which in turn is required by ISO C to be the characters 0 through 9 and nothing else. So only in C locale all [0-9], [0123456789], \d and [[:digit:]] mean exactly the same. The [0123456789] has no possible misinterpretations, [[:digit:]] is available in more utilities and it is common to mean only [0123456789]. The \d is supported by few utilities.
As for [0-9], the meaning of range expressions is only defined by POSIX in the C locale; in other locales it might be different (might be codepoint order or collation order or something else).
Difference between [0-9], [[:digit:]] and \d的更多相关文章
- 好用到没朋友的大数模板(c++) 2014-10-01 15:06 116人阅读 评论(0) 收藏
#include <iostream> #include <cstring> using namespace std; #define DIGIT 4 //四位隔开,即万进制 ...
- [转]Wing IDE 6.0 安装及算号器注册机代码
下载安装wing 选择第三个,运行算号器,输入license id 输入request id. Python 2 算号器注册机代码 import string import random import ...
- javascript:jQuery tablesorter 2.0
https://mottie.github.io/tablesorter/docs/index.html 1.GridView <%@ Page Language="C#" ...
- WingIDE6.0神秘代码
python2: import string import random import sha BASE16 = '0123456789ABCDEF' BASE30 = '123456789ABCDE ...
- Wing IDE 6.0 算号器注册机代码
我开发Python时喜欢用Wing IDE, 然后最近发现Wing IDE升级到6.0版本了, 但是之前能在5.1上用的算号器代码不能用在6.0上了, 所以就上网搜搜是否有相关算号器, 果然, 找到了 ...
- WingIDE 5.0注冊机
在wingIDE下开发python很方便,但IDE不是免费的,网上有破解的方法.请支持正版. 把下列文件CalcActivationCode.py载入到wingIDE中.LicenseID能够随便给一 ...
- 0.0.0.0 IPAddress.Any 【】127.0.0.1 IPAddress.Loopback 【】localhost
0.0.0.0 IPAddress.Any https://msdn.microsoft.com/en-us/library/system.net.ipaddress.any(v=vs.110).a ...
- 经典面试编程题--atoi()函数的实现(就是模拟手算,核心代码就一句total = 10 * total + (c - '0'); 但是要注意正负号、溢出等问题)
一.功能简介 把一个字符串转换成整数 二.linux c库函数实现 /*** *long atol(char *nptr) - Convert string to long * *Purpose: * ...
- 51 Nod1042 数字0到9的数量
1042 数字0-9的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 给出一段区间a-b,统计这个区间内0-9出现的次数. 比如 10-19 ...
- c语言NULL和0区别及NULL详解
先看下面一段代码输出什么: #include<stdo.h> int main() { int *p=NULL; printf("%s",p); } 输出<n ...
随机推荐
- 周记【距gdoi:105天】
月考果然很可怕,跪得要死. 然后这周搞(被老师坑)去搞某个程序,我和蔡大神和kpm分工搞(结果最后我也只是变成全程嘴炮). 这周有点闷,明明想快乐点但还是…… 进度慢得要死,后缀数组略神的东西.模仿了 ...
- POJ2155 Matrix 【二维线段树】
题目链接 POJ2155 题解 二维线段树水题,蒟蒻本想拿来养生一下 数据结构真的是有毒啊,, TM这题卡常 动态开点线段树会TLE[也不知道为什么] 直接开个二维数组反倒能过 #include< ...
- wait for it
- Codeforces 931.D Peculiar apple-tree
D. Peculiar apple-tree time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Windows下安装Mycat-web
Mycat-web是基于Mycat的一个性能监控工具,如:sql性能监控等. 在安装Mycat-web之前需要先安装Zookeeper: 可参考: http://blog.csdn.net/tlk20 ...
- java bigdemical比较大小
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_33451004/article/details/71247041 java中对bigdimic ...
- finally return 执行顺序问题
网上有很多人探讨Java中异常捕获机制try...catch...finally块中的finally语句是不是一定会被执行?很多人都说不是,当然他们的回答是正确的,经过我试验,至少有两种情况下fina ...
- codefoeces problem 671D——贪心+启发式合并+平衡树
D. Roads in Yusland Mayor of Yusland just won the lottery and decided to spent money on something go ...
- swift对比object-c
http://www.cocoachina.com/bbs/read.php?tid=204294 WWDC 2014上苹果再次惊世骇俗的推出了新的编程语言SWIFT( 雨燕 ), 这个消息会前没有半 ...
- Jmeter4.0启动闪退问题解决方案
jmeter:4.0 jdk版本:1.8 在Jmeter.bat的最后添加pause可以让Jmeter启动停止: 添加了pause进行强制停止在启动命令页面,查看到Jmeter报错信息如下: 第一次解 ...