[英]Remove string between 2 characters from text string
I have text string like: 我有文字字符串,如:
"abcd[e]yth[ac]ytwec"
I need just 我需要
"abcdythytwec"
What is the easiest way to do it using regex or otherwise in python? 在python中使用正则表达式或其他方法最简单的方法是什么? I am using
.split('[')
method which is cumbersome. 我正在使用
.split('[')
方法,这很麻烦。
In [11]: re.sub(r'\[.*?\]', '', 'abcd[e]yth[ac]ytwec')
Out[11]: 'abcdythytwec'
尝试使用re模块:
import re
re.sub(r'\\[[^]]*\\]', '', "abcd[e]yth[ac]ytwec")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.