vcent
V2EX  ›  2019

Python re.findall 可以匹配到为啥 re.sub 替换不掉呢?

  •  
  •   vcent · Apr 18, 2019 · 2336 views
    This topic created in 2585 days ago, the information mentioned may be changed or developed.

    上面文本

    re.findall("<!--.*-->",aa,re.S|re.M)   #这样可以全匹配到
     re.sub("<!--.*-->","",aa,re.S|re.M)    #但是这样却替换不掉 
    

    为什么呢

    2 replies    2019-04-19 08:29:47 +08:00
    SingeeKing
        1
    SingeeKing  
    PRO
       Apr 18, 2019
    re.sub("<!--.*-->","",aa,flags=re.S|re.M)

    因为第四个参数是 count
    vcent
        2
    vcent  
    OP
       Apr 19, 2019
    多谢 已解决
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1040 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 23:31 · PVG 07:31 · LAX 16:31 · JFK 19:31
    ♥ Do have faith in what you're doing.