In [199]:
import re
import pprint

pp = pprint.PrettyPrinter()

In [289]:
pattern_todotxt = r'''^
(?P<completion>x?)(\s?)
(\(?)(?P<priority>\w?)(\)?)(\s?)
(?P<completion_date>(\d{4}-\d{2}-\d{2})?)(\s?)
(?P<creation_date>(\d{4}-\d{2}-\d{2})?)(\s?)
(?P<description>.*)
$'''

regex_todotxt = re.compile(pattern_todotxt, re.X|re.I)

pattern_project_tag = r'(?P<context>@\w+)(?P<project>\+\w+)'

regex_project_tag = re.compile(pattern_project_tag, re.X|re.I)

In [290]:
match = regex_todotxt.search('x (A) 2017-08-23 2017-08-22 measure space for +shapelShelving @chapel due:2017-08-22')
pp.pprint(match.groupdict())


{'completion': 'x',
 'completion_date': '2017-08-23',
 'creation_date': '2017-08-22',
 'description': 'measure space for +shapelShelving @chapel due:2017-08-22',
 'priority': 'A'}

In [291]:
match = regex_project_tag.search('measure space for +shapelShelving @chapel due:2017-08-22')
pp.pprint(match.groupdict())


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-291-ed6c0c0ee8b4> in <module>()
      1 match = regex_project_tag.search('measure space for +shapelShelving @chapel due:2017-08-22')
----> 2 pp.pprint(match.groupdict())

AttributeError: 'NoneType' object has no attribute 'groupdict'

In [ ]: