正则表达式编译==> re.compile()
时间:2020-01-28 18:08:31
收藏:0
阅读:83
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
string = '123abc'
string_list = ["123abc","123abc123"]
# print(re.findall('\d+',string))
# pattern = re.compile('\d+') #1. 编译生成匹配规则
# print(pattern.findall(string)) # 2. 匹配数据
pattern = re.compile('\d+')
for string in string_list:
print(pattern.findall(string))
- re.findall ==> 1. 编译生成匹配规则 2. 匹配数据
会创建上下文环境,吃性能和内存 - re.compile()创建匹配规则,可以重复利用
原文:https://www.cnblogs.com/oklizz/p/12238505.html
评论(0)