Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Python

r"
^(?:\((?P<imp>[A-Z])\)\ )?(?P<dued>(?:2[0-1][0-9]{2}\-(?:0[0-9]|1[0-2])\-(?:[0-2][0-9]|3[0-1]))|\?)\ (?:\+(?P<proname>[a-zA-Z0-9]+)(?:\#(?P<pronum>[0-9]+))?\ )?(?:\$(?P<startd>2[0-1][0-9]{2}\-(?:0[0-9]|1[0-2])\-(?:[0-2][0-9]|3[0-1]))(?:\^(?P<repeat>\d*(?:D|W|M|Y)(?:\,\d*(?:D|W|M|Y)+)*))?\ )?(?P<todo>.+?(?=(?:\ (?:\@|\&))|$))(?P<contexts>(?:\ \@\S+)*)(?P<tags>(?:\ \&\S+)*)
"
gm

Description

I customized the todo.txt (see todotxt.com) normal formatting. Here is how mine works: Priority Due_Date Project#progressive_number Start_date^repeat_every Job Contexts Tags Here is an example: (A) 2016-05-24 +projectA#4 $2015-11-30^2M My todo job @context_foo @context_bar &WAIT &ANOTHER_TAG I wanted the items to be ordered by importance and due date (instead of start date). If you want to omit the due date you put a '?' sign instead. I added a progressive number for projects so you can order project-specific jobs in order of execution. I used a custom notation for start date that includes also an optional repeatition time (every day, every two months and so on) expressed like this ^2M,3D (D for days, W for weeks, M and Y). You can use more of them separated by commas and can omit the initial number (assuming one). Then there are, in this order, contexts and tags. The tags are preceded by '&' sign.

Submitted by Francesco Tosello - 8 years ago