27
V2EX  ›  问与答

一个 Python 正则替换的问题

  •  
  •   27 · Oct 7, 2017 · 1758 views
    This topic created in 3184 days ago, the information mentioned may be changed or developed.
    想做一个类似于 tokenize 的功能,目前遇到个小问题,搜了一下搜不出来,不知道用什么关键词

    举几个例子:
    I've 替换为 I 've
    yes... 替换为 yes ...

    我只知道在 sublime text 中可以用 replace,大概方法是 ([^\.'])([\.']) -> \1 \2

    不清楚在 python 中如何实现这个
    顺便也请教一下这个问题的搜索关键词是什么
    4 replies    2017-10-10 13:22:51 +08:00
    Kilerd
        1
    Kilerd  
       Oct 7, 2017
    python regex replace(sub)
    casparchen
        2
    casparchen  
       Oct 7, 2017
    如果是这样简单的替换,str.replace()多好
    wzha2008
        3
    wzha2008  
       Oct 9, 2017
    import re
    text = re.sub('yes...', 'yes ...', text)
    ptrees
        4
    ptrees  
       Oct 10, 2017
    搜 re.sub
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   870 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 1012ms · UTC 20:25 · PVG 04:25 · LAX 13:25 · JFK 16:25
    ♥ Do have faith in what you're doing.