直接学习:https://edu.csdn.net/course/play/24756/280709
正则表达式—开始结束贪婪非贪婪
import re
# 1.^:以...开头
text = 'hello world'
res = re.match('hello',text)
res = re.search('^hello',text)
print(res.group())
# 2.$:以...结尾
text = 'hello world'
res = re.search('hello$',text)
print(res.group())
text = ''
print('='*50)
res = re.search('^$',text)
print(res.group())
print('='*50)
# 3.|:匹配多个字符串或表达式
text = '1457sertrAEX'
print('='*50)
res = re.search('([0-9]|[A-Z]|[a-z])+',text)
print(res.group())
print('='*50)
# 4.贪婪和非贪婪
text = '1457'
print('='*50)
res = re.search('\d+?',text)#加?非贪婪模式,只匹配一个,不加默认下是贪婪模式,匹配多个
print(res.group())
print('='*50)
# 5.案例一:提取html标签名称
text = '<h1>这是标题</h1>'
print('='*50)
res = re.search('<.+?>',text)
print(res.group())
print('='*50)
# 6.案例二:验证一个字符是否是0-100之间的数字
# 0,1,90,100
# 01
text = '88'
print('='*50)
res = re.match('0$|[1-9]\d?$|100$',text)
print(res.group())
print('='*50)