【问题标题】:How can I remove curly brackets as well as the text inside of it as well如何删除大括号以及其中的文本
【发布时间】:2022-07-21 23:38:35
【问题描述】:

hello_world{552}.txt

{hix89}abcdefg{47181x00}.exe

如何将这些字符串输出为“hello_world.txt,abcdefg.exe” 带双引号和逗号,不带空格

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    您可以使用正则表达式并找到解决方案:

    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']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      • 2018-03-05
      • 2019-12-21
      • 2021-02-20
      • 2013-11-17
      相关资源
      最近更新 更多