Coverage for presidio_analyzer / predefined_recognizers / country_specific / germany / de_id_card_recognizer.py: 100%
9 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-29 09:03 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-29 09:03 +0000
1from typing import List, Optional
3from presidio_analyzer import Pattern, PatternRecognizer
6class DeIdCardRecognizer(PatternRecognizer):
7 """
8 Recognizes German national ID card numbers (Personalausweisnummern) using regex.
10 The German Personalausweis (nPA – neuer Personalausweis) has been issued since
11 November 2010. Its document number (Seriennummer/Dokumentennummer) is printed on
12 the front of the card and encoded in the Machine Readable Zone (MRZ).
14 Legal basis: Personalausweisgesetz (PAuswG), Personalausweisverordnung (PAuswV).
15 Data protection: DSGVO Art. 4 Nr. 1 (personenbezogene Daten), BDSG.
17 Format (nPA, since November 2010):
18 - 9 alphanumeric characters (uppercase letters and digits)
19 - Character set: letters A–Z (excluding ambiguous chars I, O, Q, S, U)
20 and digits 0–9, per ICAO Doc 9303 / BSI TR-03110
21 - Example: L01X00T47, T22000129
23 Format (old Personalausweis, before November 2010):
24 - Letter T followed by 8 digits
25 - Example: T22000129
27 :param patterns: List of patterns to be used by this recognizer
28 :param context: List of context words to increase confidence in detection
29 :param supported_language: Language this recognizer supports
30 :param supported_entity: The entity this recognizer can detect
31 """
33 PATTERNS = [
34 Pattern(
35 "Personalausweisnummer nPA (Strict ICAO charset, 9 chars)",
36 r"\b[CFGHJKLMNPRTVWXYZ][CFGHJKLMNPRTVWXYZ0-9]{7}[CFGHJKLMNPRTVWXYZ0-9]\b",
37 0.4,
38 ),
39 Pattern(
40 "Personalausweisnummer alt (T + 8 Ziffern)",
41 r"\bT\d{8}\b",
42 0.5,
43 ),
44 Pattern(
45 "Personalausweisnummer (Relaxed, 9 alphanumeric)",
46 r"\b[A-Z][A-Z0-9]{8}\b",
47 0.15,
48 ),
49 ]
51 CONTEXT = [
52 "personalausweis",
53 "ausweis",
54 "personalausweisnummer",
55 "ausweisnummer",
56 "ausweisdokument",
57 "dokumentennummer",
58 "seriennummer",
59 "npa",
60 "neuer personalausweis",
61 "personalausweisgesetz",
62 "pauwsg",
63 "bundespersonalausweis",
64 "identity card",
65 "national id",
66 ]
68 def __init__(
69 self,
70 patterns: Optional[List[Pattern]] = None,
71 context: Optional[List[str]] = None,
72 supported_language: str = "de",
73 supported_entity: str = "DE_ID_CARD",
74 name: Optional[str] = None,
75 ):
76 patterns = patterns if patterns else self.PATTERNS
77 context = context if context else self.CONTEXT
78 super().__init__(
79 supported_entity=supported_entity,
80 patterns=patterns,
81 context=context,
82 supported_language=supported_language,
83 name=name,
84 )