re模块
常用方法:
compile使用
标志位(flags)
re.I——大小写不敏感(都识别)
re.search
但只找到了一次,因此可以用findall
findall 都查询,match、search只能查询一个
注意:findall不用加group()
拿到列表内容后,可以用for循环遍历内容,也可以直接提取索引取值
注意:如果findall下是空集,要看看是不是正则写错了
re.split 表达式:split(pattern, string, maxsplit=0, flags=0)
sub() 表达式:sub(pattern, repl, string, count=0, flags=0) 替换,相等于replace()
分组
groups返回的是元组
CSV模块
writerow形式写入csv:
witerows形式写入csv: