Python: simple REgex example


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.