Polish regexes¶
Python regexes for Polish identifiers, with checksum validation: PESEL, NIP, REGON, KRS, IBAN and NRB, dowód osobisty, passport, plates and phones.
22 regexes, from regular_regexes/pl/regexes.json, called as rre.pl.<name>(text).
Personal numbers (1) · Identity documents (4) · Companies and tax (5) · Banking and payments (3) · Phones and SIM cards (5) · Places and addresses (2) · Vehicles, ships and parcels (2)
Personal numbers¶
| function | checksum validator |
|---|---|
rre.pl.pesel |
pl_pesel |
pesel¶
Polish national identification number (PESEL): 11 digits starting with the birth date, like 01451401354; only real dates of birth.
rre.pl.pesel(text)
\b\d{11}\b
Matches are checked with pl_pesel; one that fails it is dropped.
Identity documents¶
| function | checksum validator |
|---|---|
rre.pl.id_card_number |
pl_document_number |
rre.pl.mrz_id_card |
mrz_td1 |
rre.pl.mrz_passport |
mrz_td3 |
rre.pl.passport_number |
pl_document_number |
id_card_number¶
Polish identity card number (numer dowodu osobistego): three letters and six digits, with or without a space, like ABA300000 or ZZC 108201.
rre.pl.id_card_number(text)
\b[A-Z]{3} ?\d{6}\b
Matches are checked with pl_document_number; one that fails it is dropped.
mrz_id_card¶
Machine-readable zone (MRZ) of a Polish identity card, first line (ICAO TD1): 30 characters with POL as issuing country, like IDPOLZZC1082012<<<<<<<<<<<<<<<.
rre.pl.mrz_id_card(text)
(?<![A-Z0-9<])[IAC][A-Z<]POL[A-Z0-9<]{25}(?![A-Z0-9<])
Matches are checked with mrz_td1; one that fails it is dropped.
mrz_passport¶
Machine-readable zone (MRZ) of a Polish passport, second line (ICAO TD3): 44 characters with the passport number, POL as nationality, date of birth, sex and expiry date.
rre.pl.mrz_passport(text)
(?<![A-Z0-9<])[A-Z0-9<]{9}\dPOL\d{6}\d[MFX<]\d{6}\d[A-Z0-9<]{14}[\d<]\d(?![A-Z0-9<])
Matches are checked with mrz_td3; one that fails it is dropped.
passport_number¶
Polish passport number (numer paszportu): two letters and seven digits, with or without a space, like ZZ3000001.
rre.pl.passport_number(text)
\b[A-Z]{2} ?\d{7}\b
Matches are checked with pl_document_number; one that fails it is dropped.
Companies and tax¶
| function | checksum validator |
|---|---|
rre.pl.company_name |
|
rre.pl.krs_number |
|
rre.pl.nip |
pl_nip |
rre.pl.regon |
pl_regon |
rre.pl.vat_number |
pl_nip |
company_name¶
Polish company name (nazwa firmy): capitalized words followed by a legal form such as Sp. z o.o., sp.k., sp.j., S.A., S.K.A. or P.S.A., or spółka ... written out (also in capitals), like Nowak sp.j..
rre.pl.company_name(text)
(?<![\w&'.„”"-])[„"]?[A-ZĄĆĘŁŃÓŚŹŻ0-9][\w&'.„”"-]*(?:\s(?:[„"]?[A-ZĄĆĘŁŃÓŚŹŻ0-9][\w&'.„”"-]*|&|i)){0,6}\s(?:[Ss][Pp](?:ółka|\.)\s?[Zz]\s?[Oo]\.\s?[Oo]\.(?:\s?[Ss][Pp]\.\s?[Kk]\.)?|(?i:spółka (?:z ograniczoną odpowiedzialnością|akcyjna|jawna|komandytowa|komandytowo-akcyjna|partnerska))|S\.\s?A\.|SA|S\.K\.A\.|P\.S\.A\.|[Ss][Pp]\.\s?[JjKkPp]\.)(?!\w)
krs_number¶
Polish National Court Register number (numer KRS, Krajowy Rejestr Sądowy) after the keyword KRS, keyword included: ten digits, like KRS 0000123456 or KRS pod numerem 0000123456.
rre.pl.krs_number(text)
\bKRS:?\s?(?:(?:pod\s)?(?:nr\.?|numerem)\s?)?\d{10}\b
nip¶
Polish tax identification number (NIP, numer identyfikacji podatkowej): ten digits after NIP, keyword included, or on their own with dashes, like 123-456-32-18 or 123-45-63-218.
rre.pl.nip(text)
\b(?:NIP:?\s?(?:nr\.?\s?)?(?:PL\s?)?(?:\d{3}[ -]?\d{3}[ -]?\d{2}[ -]?\d{2}|\d{3}[ -]?\d{2}[ -]?\d{2}[ -]?\d{3})|(?<![\d-])(?:\d{3}-\d{3}-\d{2}-\d{2}|\d{3}-\d{2}-\d{2}-\d{3}))\b(?!-\d)
Matches are checked with pl_nip; one that fails it is dropped.
regon¶
Polish business register number (REGON) after the keyword REGON, keyword included: nine or 14 digits, like REGON: 123456785 or REGON 12345678512347.
rre.pl.regon(text)
\bREGON:?\s?(?:nr\.?\s?)?\d{9}(?:\d{5})?\b
Matches are checked with pl_regon; one that fails it is dropped.
vat_number¶
Polish VAT number (NIP UE): PL and the ten-digit NIP, together or with dashes, like PL1234563218 or PL 123-456-32-18.
rre.pl.vat_number(text)
\bPL ?(?:\d{10}|\d{3}-\d{3}-\d{2}-\d{2}|\d{3}-\d{2}-\d{2}-\d{3})\b
Matches are checked with pl_nip; one that fails it is dropped.
Banking and payments¶
| function | checksum validator |
|---|---|
rre.pl.bic |
|
rre.pl.iban |
iban |
rre.pl.nrb |
pl_nrb |
bic¶
BIC (SWIFT code) of a Polish bank: four letters, PL and two letters or digits, with an optional three-character branch code, like PKOPPLPW or BREXPLPWXXX.
rre.pl.bic(text)
\b[A-Z]{4}PL[A-Z0-9]{2}(?:[A-Z0-9]{3})?\b
iban¶
Polish IBAN: PL, two check digits and 24 digits, together or in groups of four, like PL61 1090 1014 0000 0712 1981 2874.
rre.pl.iban(text)
\bPL\d{2}(?: ?\d{4}){6}\b
Matches are checked with iban; one that fails it is dropped.
nrb¶
Polish bank account number (NRB, numer rachunku bankowego): 26 digits, the IBAN without PL, together or grouped like 61 1090 1014 0000 0712 1981 2874.
rre.pl.nrb(text)
\b\d{2}(?: ?\d{4}){6}\b
Matches are checked with pl_nrb; one that fails it is dropped.
Phones and SIM cards¶
| function | checksum validator |
|---|---|
rre.pl.iccid |
luhn |
rre.pl.imsi |
|
rre.pl.mobile_number |
phone |
rre.pl.msisdn |
phone |
rre.pl.phone_number |
phone |
iccid¶
SIM card number (ICCID) of a Polish SIM: 8948 followed by 14 to 16 digits, without spaces, like 8948021234567890126.
rre.pl.iccid(text)
\b8948\d{14,16}\b
Matches are checked with luhn; one that fails it is dropped.
imsi¶
IMSI (subscriber identity on a SIM) of a Polish network: mobile country code 260 and 12 more digits, 15 in all, like 260021234567890.
rre.pl.imsi(text)
\b260\d{12}\b
mobile_number¶
Polish mobile number (numer komórkowy): nine digits with a mobile prefix, with +48 or 0048, or with spaces or dashes like 600 123 456; only valid Polish mobile numbers.
rre.pl.mobile_number(text)
(?:(?:\+|\b00)48[\s-]?(?=(?:45|5[0137]|6[069]|7[2389]|88))|(?<![\w+-])(?<!\d[\s.-])(?<!\(0\) )(?:(?<!\d\) )|(?<=48\) ))(?=(?:45|5[0137]|6[069]|7[2389]|88)\d[\s-]))\d{3}(?:[\s-]?\d){6}\b(?![ -]\d{1,3}\b|,\d)
Matches are checked with phone (regions PL, kind mobile); one that fails it is dropped.
msisdn¶
Polish mobile number in MSISDN form, as in telecom records: 48 and the nine-digit mobile number, like 48600123456; only valid Polish mobile numbers.
rre.pl.msisdn(text)
(?<!\+)\b48(?:45|5[0137]|6[069]|7[2389]|88)\d{7}\b
Matches are checked with phone (regions PL, kind msisdn); one that fails it is dropped.
phone_number¶
Polish phone number (numer telefonu): +48 or 0048 and nine digits, landlines with a real area code like (22) 123 45 67, and mobiles like 600 123 456; only valid Polish numbers.
rre.pl.phone_number(text)
(?:(?:\+|\b00)48[\s-]?|(?<![\w+(-])(?<!\d[\s.-])(?<!\(0\) )(?:(?<!\d\) )|(?<=48\) ))(?=\(?(?:1[2-8]|2[2-59]|3[2-4]|4[1-468]|5[24-689]|6[1-3578]|7[14-7]|8[1-79]|9[145])\)?[\s-]|(?:45|5[0137]|6[069]|7[2389]|88)\d[\s-]))\(?\d{2}\)?(?:[\s-]?\d){7}\b(?![ -]\d{1,3}\b|,\d)
Matches are checked with phone (regions PL); one that fails it is dropped.
Places and addresses¶
| function | checksum validator |
|---|---|
rre.pl.postal_code_city |
|
rre.pl.street_address |
postal_code_city¶
Polish postal code (kod pocztowy) and town: two digits, a dash and three digits, then the place name, like 00-950 Warszawa or 43-300 Bielsko-Biała.
rre.pl.postal_code_city(text)
(?<![\w-])\d{2}-\d{3}\s(?!(?:PLN|EUR|USD|Euro|Zł|ZŁ)\b)[A-ZĄĆĘŁŃÓŚŹŻ][\w-]+(?: [A-ZĄĆĘŁŃÓŚŹŻ][a-ząćęłńóśźż][\w-]*){0,2}
street_address¶
Polish street address (adres): ul., al., pl. or os. (or ulica, aleja, plac, osiedle), the name and number, with the flat after a slash, m. or lok., like ul. Jana Pawła II 12/34.
rre.pl.street_address(text)
(?<![\w.])(?<!\d )(?<!et )(?i:ul\.|ulica|al\.|alej[ae]|pl\.|plac|os\.|osiedle)\s?(?:[A-ZĄĆĘŁŃÓŚŹŻ0-9][\w'-]*\.?|[a-ząćęłńóśźż]{1,5}\.)(?:\s[\w'.-]+){0,4}?\s\d+[A-Za-z]?(?:\s?/\s?\d+[A-Za-z]?)?(?:,?\s(?i:m\.|lok\.)\s?\d+[A-Za-z]?)?(?![\w/])
Vehicles, ships and parcels¶
| function | checksum validator |
|---|---|
rre.pl.aircraft_registration |
|
rre.pl.license_plate |
aircraft_registration¶
Polish aircraft registration: SP- and three letters, like SP-ABC, SP-S or SP-X and three letters for ultralights and autogyros, or four digits for gliders, like SP-3456.
rre.pl.aircraft_registration(text)
\bSP-(?:[A-Z]{3}|[SX][A-Z]{3}|[0-38]\d{3})\b
license_plate¶
Polish license plate (tablica rejestracyjna): a district code of two or three letters, starting with a voivodeship's letter, and a serial of digits and letters in the official patterns, like WA 12345, KR 1234A or KRA 1C34.
rre.pl.license_plate(text)
\b(?!(?:EN|DIN|PN)\b|DSC)[BCDEFGKLNOPRSTWZ](?:[A-Z]{1,2}[ -]?(?:\d{5}|\d{4}[ACE-HJ-NPR-Y]|\d{3}[ACE-HJ-NPR-Y][ACE-HJ-NPR-Y])|[A-Z][ -]?\d(?:[ACE-HJ-NPR-Y]\d|[ACE-HJ-NPR-Y][ACE-HJ-NPR-Y])\d{2}|[A-Z]{2}[ -]?(?:[ACE-HJ-NPR-Y]\d{3}|\d{2}[ACE-HJ-NPR-Y][ACE-HJ-NPR-Y]|\d[ACE-HJ-NPR-Y]\d{2}|\d{2}[ACE-HJ-NPR-Y]\d|\d[ACE-HJ-NPR-Y][ACE-HJ-NPR-Y]\d|[ACE-HJ-NPR-Y][ACE-HJ-NPR-Y]\d{2}))\b