xberg 1.1.5

High-performance document intelligence library for Rust. Extract text, metadata, and structured data from PDFs, Office documents, images, and 107 formats and 371 programming languages via tree-sitter code intelligence with async/sync APIs.
Documentation
//! SWIFT/BIC bank identifier detection.
//!
//! Format: 4-letter bank code + 2-letter ISO country code + 2-character
//! location code + optional 3-character branch code (total 8 or 11 chars).

use super::PatternMatch;
use crate::types::redaction::PiiCategory;
use once_cell::sync::Lazy;
use regex::Regex;

static RE_SWIFT: Lazy<Regex> =
    Lazy::new(|| Regex::new(r"\b[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?\b").expect("swift regex compiles"));

/// Find all SWIFT/BIC code spans in `text` (8 or 11 uppercase alphanumeric characters).
pub fn find_all(text: &str) -> Vec<PatternMatch> {
    RE_SWIFT
        .find_iter(text)
        .map(|m| PatternMatch {
            start: m.start(),
            end: m.end(),
            category: PiiCategory::SwiftBic,
            text: text[m.start()..m.end()].to_string(),
        })
        .collect()
}