Python extract pattern matches

前端 未结 9 1510
小蘑菇
小蘑菇 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:30

    You want a capture group.

    p = re.compile("name (.*) is valid", re.flags) # parentheses for capture groups
    print p.match(s).groups() # This gives you a tuple of your matches.
    

提交回复
热议问题