How to input a regex in string.replace?

前端 未结 7 1930
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  Happy的楠姐
    2020-11-22 07:00

    import os, sys, re, glob
    
    pattern = re.compile(r"\<\[\d\>")
    replacementStringMatchesPattern = "<[1>"
    
    for infile in glob.glob(os.path.join(os.getcwd(), '*.txt')):
       for line in reader: 
          retline =  pattern.sub(replacementStringMatchesPattern, "", line)         
          sys.stdout.write(retline)
          print (retline)
    

提交回复
热议问题