From: Mart Lubbers Date: Thu, 19 Jun 2014 11:13:23 +0000 (+0200) Subject: Regex test added X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=ceff7bd3ff32a22c75fc9e8974df5cd06647c33f;p=bsc-thesis1415.git Regex test added --- diff --git a/program/regexex/test.py b/program/regexex/test.py new file mode 100644 index 0000000..7822208 --- /dev/null +++ b/program/regexex/test.py @@ -0,0 +1,41 @@ +#!/bin/env python +# -*- coding: utf-8 -*- + +import pprint +import re + +regexes = [ + 'maandag 11 augustus 2014 19:30 - Neutral Milk Hotel', + 'dinsdag 19 augustus 2014 22:00 - Arkells', + 'maandag 24 november 2014 20:30 - Fink', + 'woensdag 19 november 2014 20:00 - Michael Schulte', + 'zondag 26 oktober 2014 21:00 - The Majority Says - Locatie: Bitterzoet', + 'maandag 15 september 2014 20:30 - Ani DiFranco', + 'maandag 13 oktober 2014 20:30 - Tarrus Riley', + 'maandag 29 december 2014 20:30 - Alain Clark - Locatie: De Duif'] + +example_regex = re.compile("""\ +(?P + [a-z]+\s # dayname + [0-9]{2}\s[a-z]+\s # month and day + [0-9]{4}\s # year + [0-9]{2}:[0-9]{2}) # time + \s-\s # separator +(?P + .*?) # act + ($|\s-\sLocatie:\s # opt. separator and location marker else line end +(?P.*)) # optional location +""", re.VERBOSE) + +for regex in regexes: + match = example_regex.search(regex) + if match: + dct = match.groupdict() + if dct['location'] is None: + dct['location'] = 'Hoofdgebouw' + for k, v in dct.iteritems(): + print '\n{}: {}'.format(k, v), + print regex + else: + print 'No match made' + pprint.pprint(regex)