Python (re)

SWIFT / BIC Code in PY

Validate SWIFT/BIC bank identifier codes — 8 chars (head office) or 11 chars (branch).

Try it in the PY tester →

Pattern

regexPY
^[A-Z]{6}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$

Python (re) code

pyPython
import re

pattern = re.compile(r"^[A-Z]{6}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$")
input_text = "DEUTDEFF"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

[A-Z]{6} matches the bank-and-country prefix. [A-Z0-9]{2} matches the location code. (?:[A-Z0-9]{3})? optionally matches the 3-character branch code, allowing both 8-char head-office BICs and 11-char branch BICs.

Examples

Input

DEUTDEFF

Matches

  • DEUTDEFF

Input

BNPAFRPPXXX

Matches

  • BNPAFRPPXXX

Input

INVALID1

No match

Same pattern, other engines

← Back to SWIFT / BIC Code overview (all engines)