#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : jack import re class reUnit(): """ 通过正则表达式获取指定字符串值方法,如果结果不唯一,则返回多个 """ def reUnit(anyStr,leftBoundaryStr,rigjtBoundaryStr): """ :param str: 完整的字符串str :param leftBoundaryStr: 左边界str :param rigjtBoundaryStr: 右边界str :return:返回正则取值结果list """ return re.findall("{}(.+?){}".format(leftBoundaryStr,rigjtBoundaryStr),anyStr) if __name__ == '__main__': str = "onlineTestCase" print(reUnit.reUnit(str,"online","Case")) #结果:['Test']