Python extract pattern matches

前端 未结 9 1602
小蘑菇
小蘑菇 2020-11-22 06:36

Python 2.7.1 I am trying to use python regular expression to extract words inside of a pattern

I have some string that looks like this

someline abc
s         


        
9条回答
  •  温柔的废话
    2020-11-22 07:15

    Here's a way to do it without using groups (Python 3.6 or above):

    >>> re.search('2\d\d\d[01]\d[0-3]\d', 'report_20191207.xml')[0]
    '20191207'
    

提交回复
热议问题