从文本字符串中删除 2 个字符之间的字符串 [英] Remove string between 2 characters from text string

查看:48
本文介绍了从文本字符串中删除 2 个字符之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的文本字符串:

I have text string like:

"abcd[e]yth[ac]ytwec"

我只需要

"abcdythytwec"

在 python 中使用正则表达式或其他方式最简单的方法是什么?我正在使用 .split('[') 方法,这很麻烦.

What is the easiest way to do it using regex or otherwise in python? I am using .split('[') method which is cumbersome.

推荐答案

In [11]: re.sub(r'\[.*?\]', '', 'abcd[e]yth[ac]ytwec')
Out[11]: 'abcdythytwec'

这篇关于从文本字符串中删除 2 个字符之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆