\ D与[0-9]在.NET正EX pressions [英] \d versus [0-9] in .NET regular expressions
问题描述
我经常看到 [0-9]
在堆栈溢出,而不是 \ D 。我问为什么,答案往往是
\ D
匹配不仅仅是 [0-9]
。那么还有什么它匹配? 此表说,它匹配十进制数字。又是怎么回事 \ p {钕}
?
I often see [0-9]
used in .NET regular expression answers on Stack Overflow instead of \d
. I’ve asked why, and the answer tends to be "\d
matches more than just [0-9]
". So what more does it match? This table says it matches decimal digits. And what about \p{Nd}
?
或者是有没有什么区别,这是因为一些其他的正则表达式引擎的只是好的做法呢?
Or is there no difference, and this is just good practice because of some other regex engine?
推荐答案
我想答案也是在的链接引用:
\ d匹配任何十进制数字。它等效于\ p {钕}定期 EX pression模式,包括标准的十进制数字0-9 作为 以及一些其他字符集的十进制数字强>
\d matches any decimal digit. It is equivalent to the \p{Nd} regular expression pattern, which includes the standard decimal digits 0-9 as well as the decimal digits of a number of other character sets.
所以 \ D
可以匹配像十进制数字在阿拉伯字符集,这将不会与匹配[0-9]
。
So \d
can match things like decimal digits in the Arabic character set, which wouldn't be matched with [0-9]
.
这篇关于\ D与[0-9]在.NET正EX pressions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!