coolair
V2EX  ›  问与答

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

  •  
  •   coolair · Apr 1, 2017 · 3922 views
    This topic created in 3510 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   ·   989 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 19:19 · PVG 03:19 · LAX 11:19 · JFK 14:19
    ♥ Do have faith in what you're doing.