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

2018 年 10 月 30 日
 miniyao

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

#(...text...)

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

...text...

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

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

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

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

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

2、sed -i '.bak' "s/^#(\(.*\))$/\1/" <filename> ;
#上面的.bak 因为实在 Mac os 环境下才使用,其他的应该不需要

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/502683

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX