CFI Code (Classification of Financial Instruments) Regex for Python
/^[A-Z]{6}$/What this pattern does
This page provides a lightweight, single-purpose regular expression for matching cfi code (classification of financial instruments), ported and verified for Python. Financial data validation has zero tolerance for false negatives — a missed invalid entry can corrupt downstream calculations. The snippet below is ready to drop into your Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.
Python Implementation
# CFI Code (Classification of Financial Instruments)
# ReDoS-safe | RegexVault — Finance > Securities & Trading
import re
cfi_code_classification_of_financial_instruments_pattern = re.compile(r'^[A-Z]{6}$')
def validate_cfi_code_classification_of_financial_instruments(value: str) -> bool:
return bool(cfi_code_classification_of_financial_instruments_pattern.fullmatch(value))
# Example
print(validate_cfi_code_classification_of_financial_instruments("ESXXXX")) # TrueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
ESXXXX | ESXXX |
OPASPS | ESXXXXX |
DBXXXX | ES1XXX |
FFXXXX | esxxxx |
RPXXXX | ES XXX |
When to use this pattern
This pattern is drawn from the Finance > Securities & Trading category and carries a ReDoS-safe certification. That matters for Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
CFI codes do not uniquely identify instruments — they classify their type. Combined with ISIN and CFI, you can unambiguously identify and classify a security.
Technical Notes
CFI codes classify financial instruments. First char: E=equity, D=debt, R=rights, O=option, F=futures, C=collective investment, P=structured, T=referential. X means 'not applicable/defined'. Used in ANNA (ISIN authority) systems.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern