php \d+ 在正则表达式中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2841550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does \d+ mean in regular expression terms?
提问by Elitmiar
I'm new to regular expressions and came accros the following \d+ . I do not exactly know what this means, please point me in the right direction.
我是正则表达式的新手,并且出现了以下 \d+ 。我不完全知道这意味着什么,请指出正确的方向。
回答by Mark Rushakoff
\dis a digit (a character in the range 0-9), and +means 1 or more times. So, \d+is 1 or more digits.
\d是一个数字(0-9 范围内的字符),+表示 1 次或多次。所以,\d+是 1 位或更多位数字。
This is about as simple as regular expressions get. You should try reading up on regular expressions a little bit more. Google has a lot of results for regular expression tutorial, for instance. Or you could try using a tool like the free Regex Coachthat will let you enter a regular expression and sample text, then indicate what (if anything) matches the regex.
这和正则表达式一样简单。你应该多读一点正则表达式。例如,Google 有很多关于正则表达式教程的结果。或者,您可以尝试使用免费的Regex Coach 之类的工具,它可以让您输入正则表达式和示例文本,然后指出与正则表达式匹配的内容(如果有的话)。
回答by Jakub Hampl
\dis called a character class and will match digits. It is equal to [0-9].
\d称为字符类,将匹配数字。它等于[0-9]。
+matches 1 or more occurrences of the character before.
+匹配 1 个或多个之前出现的字符。
So \d+means match 1 or more digits.
所以\d+意味着匹配 1 个或多个数字。
回答by Harmen
\dmeans 'digit'. +means, '1 or more times'. So \d+means one or more digit. It will match 12and 1.
\d意思是“数字”。+意思是“1 次或多次”。所以\d+意味着一位或多位数字。它将匹配12和1。
回答by Mark Baker
\d is a digit, + is 1 or more, so a sequence of 1 or more digits
\d 是一个数字,+ 是 1 个或更多,所以 1 个或多个数字的序列

