Python str.strip() with regex filtering unexpected characters

前端 未结 6 830
广开言路
广开言路 2020-12-19 22:58

I\'m running into an issue that I hope is simple, however I\'ve run into a wall trying to figure it out. I\'m attempting to strip the DateTime timestamp from the beginning

6条回答
  •  盖世英雄少女心
    2020-12-19 23:28

    if you have repeat items with same pattern in your string, you can use regex find all the match then replace it to empty string

    import re
    pattern = r'\[\w{3} \w{3} \d{2} \d{2}:\d{2}:\d{2} \d{4}\] '
    for p in re.findall(pattern,line):
       line = line.replace(p,'')
    

提交回复
热议问题