Coverage for presidio_analyzer / predefined_recognizers / country_specific / uk / uk_nino_recognizer.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-29 09:03 +0000

1from typing import List, Optional 

2 

3from presidio_analyzer import Pattern, PatternRecognizer 

4 

5 

6class UkNinoRecognizer(PatternRecognizer): 

7 """ 

8 Recognizes UK National Insurance Number using regex. 

9 

10 :param patterns: List of patterns to be used by this recognizer 

11 :param context: List of context words to increase confidence in detection 

12 :param supported_language: Language this recognizer supports 

13 :param supported_entity: The entity this recognizer can detect 

14 """ 

15 

16 PATTERNS = [ 

17 Pattern( 

18 "NINO (medium)", 

19 r"\b(?!bg|gb|nk|kn|nt|tn|zz|BG|GB|NK|KN|NT|TN|ZZ) ?([a-ceghj-pr-tw-zA-CEGHJ-PR-TW-Z]{1}[a-ceghj-npr-tw-zA-CEGHJ-NPR-TW-Z]{1}) ?([0-9]{2}) ?([0-9]{2}) ?([0-9]{2}) ?([a-dA-D{1}])\b", # noqa: E501 

20 0.5, 

21 ), 

22 ] 

23 

24 CONTEXT = ["national insurance", "ni number", "nino"] 

25 

26 def __init__( 

27 self, 

28 patterns: Optional[List[Pattern]] = None, 

29 context: Optional[List[str]] = None, 

30 supported_language: str = "en", 

31 supported_entity: str = "UK_NINO", 

32 name: Optional[str] = None, 

33 ): 

34 patterns = patterns if patterns else self.PATTERNS 

35 context = context if context else self.CONTEXT 

36 super().__init__( 

37 supported_entity=supported_entity, 

38 patterns=patterns, 

39 context=context, 

40 supported_language=supported_language, 

41 name=name, 

42 )