import re
#常规匹配
content = \'Hello 1234567 World_This is a Regex Demo\'
#result = re.match(\'^Hello\s\d\d\d\s\d{4}\s\w{10}.*Demo$\',content)
#print(result.group())
#print(result.span())
#泛匹配
#result = re.match("^Hello.*Demo$",content)
#print(result)
#目标匹配
#result = re.match(\'^Hello\s(\d+)\sWorld.*Demo$\',content)
#print(result.group(1))
#贪婪(匹配尽可能多的字符)
#result = re.match(\'^He.*(\d+).*Demo$\',content)
#非贪婪
#result = re.match(\'^He.*?(\d+).*Demo$\',content)
#print(result.group(1))
#匹配模式(存在换行符)
#result = re.match(\'^He.*?(\d+).*Demo$\',content,re.S)
#转义\
#总结:尽量使用泛匹配,使用括号得到匹配目标,尽量使用非贪婪模式,有换行re.S
#re.search()扫描整个字符串并返回第一个匹配,match开头需要一样的
#re.findall(), 返回所有匹配的
#re.sub()替换
#re.compile()编译正则表达式对象
相关文章:
- Python爬虫 正则表达式 2021-10-01
- python爬虫正则表达式 2021-10-01
- Python 爬虫-正则表达式 2021-10-01
- python爬虫-正则表达式 2021-10-01
- python爬虫之正则表达式 2021-11-03
- python爬虫(三)-正则表达式 2021-08-04
- Python爬虫与正则表达式 2021-05-19
- python爬虫05正则表达式 2021-10-21