“\d”正则表达式是指数字? [英] Does "\d" in regex mean a digit?

查看:263
本文介绍了“\d”正则表达式是指数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在 123 中, \d 匹配 1 3 而不是 2 。我想知道如果 \d 匹配符合什么样的要求的数字?我在说Python风格正则表达式。

I found that in 123, \d matches 1 and 3 but not 2. I was wondering if \d matches a digit satisfying what kind of requirement? I am talking about Python style regex.

Gedit中的正则表达式插件使用的是Python风格的正则表达式。我创建了一个文本文件,其内容是

Regular expression plugin in Gedit is using Python style regex. I created a text file with its content being

123

只有 1 3 被正则表达式 \d ; 2 不是。

Only 1 and 3 are matched by the regex \d; 2 is not.

通常,对于没有其他字符的数字序列序列,只有奇数位数是匹配,偶数位数不是。例如,在 12345 中,比赛是 1 3 5

Generally for a sequence of digit numbers without other characters in between, only the odd order digits are matches, and the even order digits are not. For example in 12345, the matches are 1, 3 and 5.

推荐答案

[0-9] 并不总是等价的 \d 。在python3中, [0-9] 只匹配 0123456789 个字符,而 \d 匹配 [0-9] 和其他数字字符,例如东部阿拉伯数字 0123456789

[0-9] is not always equivalent to \d. In python3, [0-9] matches only 0123456789 characters, while \d matches [0-9] and other digit characters, for example Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩.

这篇关于“\d”正则表达式是指数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆