菜鸟IT的博客 >> Python
正则表达式查找字符串 | import re | JieGuo2=re.search(r"\d","www.17wx.net") | \d代表1个数字
# -*- coding: utf-8 -*-
# 导入正则表达式的库
import re
JieGuo1=re.search(r"17wx","www.17wx.net")
print(JieGuo1)
print(JieGuo1.span())
# 查找1个数字,\d
JieGuo2=re.search(r"\d","www.17wx.net")
print(JieGuo2)
# 查找2个数字,\d\d
JieGuo2=re.search(r"\d\d","www.17wx.net")
print(JieGuo2)
# 查找4个数字,\d\d\d
JieGuo3=re.search(r"\d\d\d","www.17wx.net")
print(JieGuo3)
——————————
输出结果:
<_sre.SRE_Match object; span=(4, 8), match='17wx'>
(4, 8)
<_sre.SRE_Match object; span=(4, 5), match='1'>
<_sre.SRE_Match object; span=(4, 6), match='17'>
None
Process finished with exit code 0
菜鸟IT博客[2022.01.29-13:06] 访问:255