Posted By

magicrebirth on 01/17/10


Tagged

regex re


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

silang


Python: simple REgex example


 / Published in: Python
 

  1. >>> s
  2. '1/Mar/1215'
  3. >>> pattern = r"(\d+)"
  4. >>> re.match(pattern, s).groups()
  5. ('1',)
  6. >>> pattern = r"(\d+)/(Sept|Mar)/(\d+)"
  7. >>> re.match(pattern, s).groups()
  8. ('1', 'Mar', '1215')

Report this snippet  

You need to login to post a comment.