InRegex Logo
InRegex

Match American Social Security Number

Explication

This regex pattern matches American Social Security Numbers. It first uses \b to match word boundaries. Then it uses negative lookahead assertions to exclude invalid SSN patterns like ones starting with 000, 666, or in the 900-999 range. It then matches the standard SSN format of '###-##-####'.

python

Expression Régulière

\\b(?!000|666|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0000)\\d{4}\\b
Copier
Avez-vous des Retours ?
python

Exemple d'Utilisation

import re

ssn_pattern = r'\b(?!000|666|9\d{2})\d{3}-(?!00)\d{2}-(?!0000)\d{4}\b'
ssn = '123-45-6789'
if re.match(ssn_pattern, ssn):
    print('Valid SSN')
Copier

Testez l'expression

Expressions Régulières Similaires