Last active
October 17, 2016 17:16
-
-
Save miroli/f0b2755dfc9107871354f34c7ce1a049 to your computer and use it in GitHub Desktop.
Regex fun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| import re | |
| # Matchar två eller tre namn, kapitaliserade eller med bara versaler | |
| name_re = re.compile(r'((?:[A-ZÅÄÖ]+[a-zåäöéèü]*\s*){2,3})') | |
| # Exkludera PARTER och MOTPART | |
| text = 'PARTER Janne MICKY Svensson' | |
| matches = name_re.findall(text.replace('PARTER', '').replace('MOTPART', '')) | |
| # Matchar personnummer i formen XXXXXX-YYYY med eller utan | |
| # oändligt många whitespace-tecken mellan siffrorna och bindestrecket. | |
| num_re = re.compile(r'[0-9\s]{6,}\s*-\s*[0-9\s]{4,}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment