【发布时间】:2022-07-21 23:38:35
【问题描述】:
hello_world{552}.txt
{hix89}abcdefg{47181x00}.exe
如何将这些字符串输出为“hello_world.txt,abcdefg.exe” 带双引号和逗号,不带空格
【问题讨论】:
标签: python python-3.x
hello_world{552}.txt
{hix89}abcdefg{47181x00}.exe
如何将这些字符串输出为“hello_world.txt,abcdefg.exe” 带双引号和逗号,不带空格
【问题讨论】:
标签: python python-3.x
您可以使用正则表达式并找到解决方案:
output=[]
test=['hello_world{552}.txt','{hix89}abcdefg{47181x00}.exe']
for x in test:
out = re.sub('{\w*}','',x)
output.append(out)
print(output)
输出:
['hello_world.txt', 'abcdefg.exe']
【讨论】: