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)
相关推荐
CN.LG12 分钟前
浅谈C#之SynchronizationContext
开发语言·c#
一只小小程序猿14 分钟前
Python计算机视觉编程 第九章 图像分割
开发语言·python·计算机视觉
武昌库里写JAVA15 分钟前
人工智能不是人工“制”能
c语言·开发语言·数据结构·算法·二维数组
AI原吾19 分钟前
探索Mem0:AI的智能记忆层
人工智能·python·ai·mem0
azhou的代码园2 小时前
基于JAVA+SpringBoot+Vue的医院资源管理系统
java·开发语言·vue.js·spring boot·毕业设计·医院资源管理
C7211BA2 小时前
多智能体强化学习示例
python
蔚一2 小时前
Java面向对象——内部类(成员内部类、静态内部类、局部内部类、匿名内部类,完整详解附有代码+案例)
java·开发语言·数据结构·分类
all the time once2 小时前
谷神后端list转map
开发语言
吱吱鼠叔3 小时前
MATLAB绘图:4.统计图表
开发语言·matlab
爱喝热水的呀哈喽3 小时前
需求导向的正则表达式
开发语言·前端