Archive for March, 2009

python regex

Wednesday, March 25th, 2009

I don't know why, but I never knew about the grouping that was possible in Python's re module. I've been using Python this long and suddenly realize it's there... a true facepalm moment. Anyway, how's this for cool? -

PYTHON:
  1. import re
  2. string = "S03E12 - A random filename"
  3. print re.match(r'.*S(?P<season>\d+).*E(?P<episode>\d+)', string).groupdict()