US Social Security Number
Match US Social Security Numbers in the canonical XXX-XX-XXXX format.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\b\\d{3}-\\d{2}-\\d{4}\\b", "g");
const input = "123-45-6789";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\b\d{3}-\d{2}-\d{4}\b")
input_text = "123-45-6789"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b\d{3}-\d{2}-\d{4}\b`)
input := `123-45-6789`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
\b\d{3}-\d{2}-\d{4}\b (flags: g)Raw source: \b\d{3}-\d{2}-\d{4}\b
How it works
Examples
Input
123-45-6789Matches
123-45-6789
Input
SSN: 987-65-4321 on fileMatches
987-65-4321
Input
123456789No match
—Common use cases
- •PII detection in logs or documents
- •Data loss prevention (DLP) scanning
- •Form field validation in US apps
- •Redaction pipelines for compliance
Related patterns
Credit Card Number
ValidationMatch 16-digit credit card numbers with optional spaces or hyphens between groups of 4.
International Phone Number (Loose)
ValidationMatch international phone numbers in a variety of loose formats including country codes, area codes, and separators.
US Phone Number
ValidationMatch US phone numbers in common formats: (555) 867-5309, 555-867-5309, 5558675309.
IBAN (International Bank Account Number)
ValidationValidate IBAN bank account identifiers: 2-letter country code, 2 check digits, 11–30 alphanumerics.