python 正则表达式

复制代码
import re

s = "hello world"
result = re.match("hello",s)
print(result)
print(result.span())
print(result.group())
复制代码
import re

s = "hello world"
result = re.match("hello",s)
print(result)
print(result.span())
print(result.group())
s = "good hello world"
result = re.search("hello",s)
print(result)


s = "good hello world  hello earth"
result = re.findall("hello",s)
print(result)

复制代码
import re

s = "hello world"
result = re.match("hello",s)
print(result)
print(result.span())
print(result.group())
s = "good hello world"
result = re.search("hello",s)
print(result)


s = "good hello world  hello earth"
result = re.findall("hello",s)
print(result)

s = "aaajkjl dja123jkjhj#hjkhd3444@"
result = re.findall(r'\d',s)#r 表示是正常子符
print(result)
result = re.findall(r'\W',s)# 特殊字符
print(result)

result = re.findall(r'[a-zA-Z 2-3]',s)
print(result)

#^ 开头 结尾
r = '^[0-9a-zA-Z]{6,10}$'
#满足条件
s = "123456yys"
result = re.findall(r,s)
print(result)
#不满足条件
s = "123456yys*"
result = re.findall(r,s)
print(result)


r = '^[1-9][0-9]{4,10}$'
#满足条件
s = "35878986"
result = re.findall(r,s)
print(result)
#不满足条件
s = "035878986"
result = re.findall(r,s)
print(result)

r = r'(^[\w-]+(\.[\w-]*)*@(qq|163|gmail)(\.[\w-]*)+$)'
s = "a.b.e.f.g@qq.com.e.c"
result = re.findall(r,s)
print(result)
result = re.match(r,s)
print(result)

s = "a.b.e.f.g@123.com.e.c"
result = re.findall(r,s)
print(result)
result = re.match(r,s)
print(result)
相关推荐
VBA633715 分钟前
如何学习VBA:换一种思路思考问题,利用数据库实现数据处理自动化
开发语言
0_0梅伊阁诗人26 分钟前
Django ORM 模型
开发语言·数据库·笔记·python·oracle·django
林夕忆梦_猫1 小时前
初识C++
开发语言·c++
lightqjx1 小时前
【C++】string类 模拟实现
java·开发语言·c++
Genevieve_xiao1 小时前
【dl】python基础 深度学习中需要用到的python基础
python·深度学习
m0_578267861 小时前
从零开始的python学习(九)P142+P143+P144+P145+P146
笔记·python·学习
只_只1 小时前
B1013 PAT乙级JAVA题解 数素数
java·开发语言
minji...1 小时前
C++ list的模拟实现
开发语言·c++·list
is08151 小时前
You Only Look Once
python
zqy02271 小时前
HTTP的Web服务测试在Python中的实现
python·网络协议·http