V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
vcent
V2EX  ›  2019

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

  •  
  •   vcent · Apr 18, 2019 · 2309 views
    This topic created in 2577 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   ·   3305 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 10:46 · PVG 18:46 · LAX 03:46 · JFK 06:46
    ♥ Do have faith in what you're doing.