coolair
V2EX  ›  问与答

Python 如何替换一个字符串中多个连续的空格换行制表符为一个空格?

  •  
  •   coolair · Apr 1, 2017 · 3934 views
    This topic created in 3515 days ago, the information mentioned may be changed or developed.
    4 replies  •  2017-04-01 10:30:34 +08:00
    40huo
    40huo
    Apr 1, 2017
    1
    正则?
    z4none
    z4none
    Apr 1, 2017 via Android
    2
    split
    join
    LichMscy
    LichMscy
    Apr 1, 2017
    3
    m = re.findall('[^\s]+', inputStr, re.S)
    n = ''.join(m)
    coolair
    coolair
    OP
    Apr 1, 2017
    4
    import re
    pat = re.compile(r'\s+')
    s = ' \t foo \t bar \t '
    print pat.sub('', s)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1030 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:15 · PVG 02:15 · LAX 10:15 · JFK 13:15
    ♥ Do have faith in what you're doing.