正则表达式编译==> 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))

原文:https://www.cnblogs.com/oklizz/p/12238505.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!