代码之家  ›  专栏  ›  技术社区  ›  notacorn

如何在python中应用循环模式regex?

  •  0
  • notacorn  · 技术社区  · 5 年前

    我正在尝试使用以下正则表达式 (.+?)\1+ regexr

    enter image description here

    但当我试图用 re re.search

    >>> re.search("1", "1")
    <re.Match object; span=(0, 1), match='1'>
    >>> re.search("(.+?)\1+", "111111")
    >>> 
    

    为什么这个正则表达式不能在python中工作?

    1 回复  |  直到 5 年前
        1
  •  1
  •   Astik Gabani    5 年前

    尝试使用以下行:

    re.search(r"(.+?)\1+", "111111")