一、正则表达式(一种文本模式,描述在搜索文本时要匹配的一个或多个字符串)
典型场景:数据验证;文本扫描;文本提取;文本替换;文本分割
语法:特殊符号与字符
二、.
.findall():查找所有非重复匹配项;返回list
.math(string[,pos[,endpos]]):匹配,仅从起始位置;返回MathObject
.search(string[,pos[,endpos]]):任意位置搜索;返回MathObject
.finditer():查找所有匹配项,返回包括MatchObject元素的迭代器
三、正则模块之MatchObject
>import re
>text='Tom is 8 years old.Jerry is 23 years old'
>pattern=re.compile(r'\d+')
>pattern.findall(text)
['8','23'] #输出的是字符
>pattern==re.compile(r'(\d+).*?(\d+)')
四、系统模块
sys提供一组功能映射Python运行时的操作系统
os提供跨平台可移植的操作系统编程接口。os.path 提供文件及目录工具的可移植编程接口
sys模块
>import sys
>dir(sys)