鱼C论坛

 找回密码
 立即注册
查看: 1753|回复: 5

[已解决]正则表达式

[复制链接]
发表于 2020-2-15 11:21:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
在re.research()方法中
第一个参数用正则表达式
而\d表示匹配0~9所有数字
但是为什么 \d\d\d 表示范围 000~99呢?
不应该是000~999吗
最佳答案
2020-2-15 12:51:16
help(re):匹配数字,等效[0-9]。3个\d应该就是 000-999,贴下代码,看下实际问题。
        \d       Matches any decimal digit; equivalent to the set [0-9] in
                 bytes patterns or string patterns with the ASCII flag.
                 In string patterns without the ASCII flag, it will match the whole
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-2-15 11:24:42 | 显示全部楼层
你的描述是000-999,但是ip匹配应该不是这么写的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-2-15 11:30:32 | 显示全部楼层
塔利班 发表于 2020-2-15 11:24
你的描述是000-999,但是ip匹配应该不是这么写的

为啥在匹配ip的时候\d\d\d表示000~99
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-15 11:46:44 | 显示全部楼层
我就是猛辣 发表于 2020-2-15 11:30
为啥在匹配ip的时候\d\d\d表示000~99

你看错了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-15 12:40:56 From FishC Mobile | 显示全部楼层
\d表示是1-9中的一个数字。 \d\d\d表示匹配3个数字,最大匹配999,最小匹配000。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-2-15 12:51:16 | 显示全部楼层    本楼为最佳答案   
help(re):匹配数字,等效[0-9]。3个\d应该就是 000-999,贴下代码,看下实际问题。
        \d       Matches any decimal digit; equivalent to the set [0-9] in
                 bytes patterns or string patterns with the ASCII flag.
                 In string patterns without the ASCII flag, it will match the whole
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-20 19:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表