推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
miniyao
V2EX  ›  Python

用什么方法,能最快的把一行文字头尾的符号(...text...)去掉?

  •  
  •   miniyao · Oct 30, 2018 · 2677 views
    This topic created in 2757 days ago, the information mentioned may be changed or developed.

    文稿中,有很多文字是用括号(...text...)框起来的,括号前面有 # 的那一行,类似这样:

    #(...text...)
    

    须要把 # 连()一起剥去,剩下:

    ...text...
    

    没有 # 开头的那一行,括号(...text...)继续保留不动。

    20 replies    2018-11-05 17:02:53 +08:00
    neoblackcap
        1
    neoblackcap  
       Oct 30, 2018 via iPhone
    自己写一个解析器,快速跑一下。
    不用解析的方法,可能会出错
    hqs0417
        2
    hqs0417  
       Oct 30, 2018
    全文替换,正则表达式,比如说用 vscode
    ywgx
        3
    ywgx  
       Oct 30, 2018 via iPhone
    对 vim 来说 录制个宏,播放即可,估计也就几秒吧
    cname
        4
    cname  
       Oct 30, 2018 via Android
    sublime text 搜索#,选择所有,删除
    cname
        5
    cname  
       Oct 30, 2018 via Android
    审题失败,打扰了😷
    lniwn
        6
    lniwn  
       Oct 30, 2018
    任意一个支持正则的编辑器都能做到,楼主有尝试过吗?
    wsh1108
        7
    wsh1108  
       Oct 30, 2018 via Android
    随便一个支持正则的编辑器
    cname
        8
    cname  
       Oct 30, 2018 via Android
    应该是搜索#( 然后选择所有,删除,向右移动光标,删除)
    wsh1108
        9
    wsh1108  
       Oct 30, 2018 via Android
    @lniwn 尴尬😅,看到你发,我就不回了
    Akkuman
        10
    Akkuman  
       Oct 30, 2018 via Android
    notepad++正则替换 \#\((.*)\)替换为$1
    co3site
        11
    co3site  
       Oct 30, 2018 via Android
    text.lstrip('#(').ratio(')')
    co3site
        12
    co3site  
       Oct 30, 2018 via Android
    @co3site 手机打字,手残了。。。
    text.lstrip('#(').rstrip(')')
    sutra
        13
    sutra  
       Oct 30, 2018
    $ cat a
    #(hello)world
    #(he(llo)world
    (hello)world

    $ cat a | sed 's/^#(\(.*\))/\1/'
    helloworld
    he(lloworld
    (hello)world
    sutra
        14
    sutra  
       Oct 30, 2018   ❤️ 1
    上面的回复可能审题错误。

    $ cat a
    #hello(hello)world
    #hello(he(llo)world
    (hello)world

    $ cat a | sed 's/^#\(.*\)(\(.*\))/\1\2/'
    hellohelloworld
    hello(helloworld
    (hello)world
    loryyang
        15
    loryyang  
       Oct 30, 2018
    解法同 13 楼,注意区分下中英文字符就行。好好学正则啊,非常有用
    ryd994
        16
    ryd994  
       Oct 31, 2018 via Android
    就算不用正则,用 Python 也就是一个 for 一个 if 的事………
    TangMonk
        17
    TangMonk  
       Oct 31, 2018
    aaaaasam
        18
    aaaaasam  
       Nov 5, 2018
    1、vim 打开文件:%s/^\#(\(.*\))$/\1/
    aaaaasam
        19
    aaaaasam  
       Nov 5, 2018
    1
    aaaaasam
        20
    aaaaasam  
       Nov 5, 2018
    。。。ctrl + 回车不是换行。。。
    1、用 vim 打开文件,然后进入命令模式,输入 %s/^\#(\(.*\))$/\1/ 回车就好了

    2、sed -i '.bak' "s/^#(\(.*\))$/\1/" <filename> ;
    #上面的.bak 因为实在 Mac os 环境下才使用,其他的应该不需要
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5052 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 85ms · UTC 01:13 · PVG 09:13 · LAX 18:13 · JFK 21:13
    ♥ Do have faith in what you're doing.