标签:环境 list dal imp 生成 正则表达 表达式 设置 bin
#!/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))
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
string = '''
abcd
abcd
'''
pattern = re.compile('a(.*?)d') # 非贪婪 ['bc', 'bc']
pattern = re.compile('a(.*)d') # 贪婪 ['bc', 'bc']
pattern = re.compile('a(.*)d',re.RegexFlag.S) # DOTALL模式 ['bcd\n abc']
print(pattern.findall(string))
标签:环境 list dal imp 生成 正则表达 表达式 设置 bin
原文地址:https://www.cnblogs.com/oklizz/p/12238505.html