如何使用正则表达式删除字符串的一部分

问题描述 投票:-3回答:1

我正在使用re.py,并希望删除字符串的所有部分,包括并以“-”开头,直到不包括“ \ n”为止

例如:

我有:

aaa bbb ccc-uuuuu vvvvv \ n

ddd eee fff-wwwww xxxxx \ n

ggg hhh iii-yyyyy zzzzz \ n

期望:

aaa bbb ccc \ n

ddd eee fff \ n

ggg hhh iii \ n

python regex python-3.x code-snippets
1个回答
0
投票

使用str.replace。不需要re

text.replace('--', '').strip()
© www.soinside.com 2019 - 2024. All rights reserved.