How to input a regex in string.replace?

前端 未结 7 1922
佛祖请我去吃肉
佛祖请我去吃肉 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:08

    don't have to use regular expression (for your sample string)

    >>> s
    'this is a paragraph with<[1> in between and then there are cases ... where the<[99> number ranges from 1-100. \nand there are many other lines in the txt files\nwith<[3> such tags \n'
    
    >>> for w in s.split(">"):
    ...   if "<" in w:
    ...      print w.split("<")[0]
    ...
    this is a paragraph with
     in between
     and then there are cases ... where the
     number ranges from 1-100
    .
    and there are many other lines in the txt files
    with
     such tags
    

提交回复
热议问题