• Python中re.findall的贪心和非贪心算法


    Python中re.findall的贪心和非贪心算法:

    import re
    s1='hjxxHelloxxrynxxPythonxxplk'
    f1=re.findall('xx.*xx',s1)
    print(f1)
    f2=re.findall('xx.*?xx',s1)
    print(f2)
    f3=re.findall('xx(.*)xx',s1)
    print(f3)
    f4=re.findall('xx(.*?)xx',s1)
    print(f4)
    s2='''hjxxHello
    xxrynxxPythonxxplk'''
    g1=re.findall('xx(.*?)xx',s2)
    print(g1)
    g2=re.findall('xx(.*?)xx',s2,re.S)
    print(g2)

    输出为:

    ['xxHelloxxrynxxPythonxx']
    ['xxHelloxx', 'xxPythonxx']
    ['HelloxxrynxxPython']
    ['Hello', 'Python']
    ['ryn']
    ['Hello ', 'Python']

  • 相关阅读:
    Windows下使用nmake编译C/C++的makefile
    poj 1228
    poj 1039
    poj 1410
    poj 3304
    poj 1113
    poj 2074
    uva 1423 LA 4255
    poj 1584
    poj 3277
  • 原文地址:https://www.cnblogs.com/zhangziyan/p/9114803.html
Copyright © 2020-2023  润新知