vcent
V2EX  ›  2019

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

  •  
  •   vcent · Apr 18, 2019 · 2601 views
    This topic created in 2694 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   ·   Privacy   ·   Solana   ·   3266 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 12:15 · PVG 20:15 · LAX 05:15 · JFK 08:15
    ♥ Do have faith in what you're doing.