How to input a regex in string.replace?

前端 未结 7 1920
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 06:50

I need some help on declaring a regex. My inputs are like the following:

this is a paragraph with<[1> in between and then there are cases ..         


        
7条回答
  •  温柔的废话
    2020-11-22 07:19

    The easiest way

    import re
    
    txt='this is a paragraph with<[1> in between and then there are cases ... where the<[99> number ranges from 1-100.  and there are many other lines in the txt files with<[3> such tags '
    
    out = re.sub("(<[^>]+>)", '', txt)
    print out
    

提交回复
热议问题