DD
DevDash

Regex for SWIFT/BIC Code

Regex Pattern

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

SWIFT/BIC bank identifier code (8 or 11 characters)

Quick Answer

The regex pattern for swift/bic code is `^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$`. SWIFT/BIC bank identifier code (8 or 11 characters). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
DEUTDEFF✓ Matches
BNPAFRPPXXX✓ Matches
CHASUS33✓ Matches
DEUT✗ No match
12345678✗ No match
deutdeff✗ No match

Code Examples

javascript

const regex = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$/;
const isValid = regex.test(value);

python

import re
pattern = r'^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$/', $value)) {
    echo "valid";
}

java

String pattern = "^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.