Regex Named Capture Groups

Collection of regex patterns using named capture groups for extracting structured data from text. Named groups make patterns more readable and maintainable by assigning meaningful names to captured portions.

📝 Date Parsing Patterns regex

🟢 simple ⭐⭐

Extract date components (year, month, day) from various date formats using named capture groups

⏱️ 5 min 🏷️ date, parsing, datetime, formatting
# Date Parsing with Named Groups
# Extract year, month, and day from date strings

# ISO 8601 Format (YYYY-MM-DD)
# Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
# Input: 2025-01-16
# Groups: year=2025, month=01, day=16
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})

# US Format (MM/DD/YYYY)
# Pattern: (?<month>\d{2})/(?<day>\d{2})/(?<year>\d{4})
# Input: 01/16/2025
# Groups: month=01, day=16, year=2025
(?<month>\d{2})/(?<day>\d{2})/(?<year>\d{4})

# European Format (DD.MM.YYYY)
# Pattern: (?<day>\d{2})\.(?<month>\d{2})\.(?<year>\d{4})
# Input: 16.01.2025
# Groups: day=16, month=01, year=2025
(?<day>\d{2})\.(?<month>\d{2})\.(?<year>\d{4})

# Textual Month (YYYY-Mon-DD)
# Pattern: (?<year>\d{4})-(?<month>[A-Za-z]{3})-(?<day>\d{2})
# Input: 2025-Jan-16
# Groups: year=2025, month=Jan, day=16
(?<year>\d{4})-(?<month>[A-Za-z]{3})-(?<day>\d{2})

# Full Month Name
# Pattern: (?<month>[A-Za-z]+) (?<day>\d{1,2}), (?<year>\d{4})
# Input: January 16, 2025
# Groups: month=January, day=16, year=2025
(?<month>[A-Za-z]+) (?<day>\d{1,2}), (?<year>\d{4})

# ISO with Time
# Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2})
# Input: 2025-01-16T14:30
# Groups: year=2025, month=01, day=16, hour=14, minute=30
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2})

📝 Time Parsing Patterns regex

🟢 simple ⭐⭐

Extract time components (hour, minute, second) from various time formats

⏱️ 5 min 🏷️ time, parsing, datetime, formatting
# Time Parsing with Named Groups
# Extract hour, minute, second from time strings

# 24-Hour Format (HH:MM:SS)
# Pattern: (?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})
# Input: 14:30:45
# Groups: hour=14, minute=30, second=45
(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})

# 12-Hour Format with AM/PM
# Pattern: (?<hour>\d{1,2}):(?<minute>\d{2}):(?<second>\d{2}) (?<ampm>[AP]M)
# Input: 2:30:45 PM
# Groups: hour=2, minute=30, second=45, ampm=PM
(?<hour>\d{1,2}):(?<minute>\d{2}):(?<second>\d{2}) (?<ampm>[AP]M)

# Hours and Minutes Only
# Pattern: (?<hour>\d{2}):(?<minute>\d{2})
# Input: 14:30
# Groups: hour=14, minute=30
(?<hour>\d{2}):(?<minute>\d{2})

# Time with Milliseconds
# Pattern: (?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})\.(?<ms>\d{3})
# Input: 14:30:45.123
# Groups: hour=14, minute=30, second=45, ms=123
(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})\.(?<ms>\d{3})

# ISO 8601 Time
# Pattern: (?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(?<tz>[+-]\d{2}:\d{2})
# Input: 14:30:45+05:30
# Groups: hour=14, minute=30, second=45, tz=+05:30
(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(?<tz>[+-]\d{2}:\d{2})

📝 IP Address Parsing Patterns regex

🟢 simple ⭐⭐

Extract IP address octets and components from IPv4 addresses

⏱️ 6 min 🏷️ network, ip, parsing, addressing
# IP Address Parsing with Named Groups
# Extract octets from IPv4 addresses

# Standard IPv4
# Pattern: (?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3})
# Input: 192.168.1.1
# Groups: octet1=192, octet2=168, octet3=1, octet4=1
(?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3})

# IP with CIDR Notation
# Pattern: (?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3})/(?<cidr>\d{1,2})
# Input: 192.168.1.0/24
# Groups: octet1=192, octet2=168, octet3=1, octet4=0, cidr=24
(?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3})/(?<cidr>\d{1,2})

# IP with Port
# Pattern: (?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3}):(?<port>\d{1,5})
# Input: 192.168.1.1:8080
# Groups: octet1=192, octet2=168, octet3=1, octet4=1, port=8080
(?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3}):(?<port>\d{1,5})

# Network and Broadcast
# Pattern: (?<network>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/(?<cidr>\d{1,2}) (?:broadcast: (?<broadcast>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))
# Input: 192.168.1.0/24 broadcast: 192.168.1.255
# Groups: network=192.168.1.0, cidr=24, broadcast=192.168.1.255
(?<network>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/(?<cidr>\d{1,2}) (?:broadcast: (?<broadcast>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))

📝 URL Parsing Patterns regex

🟡 intermediate ⭐⭐⭐

Extract URL components (protocol, domain, path, query, fragment) from URLs

⏱️ 10 min 🏷️ url, parsing, web, http
# URL Parsing with Named Groups
# Extract protocol, domain, path, query, fragment from URLs

# Basic URL Structure
# Pattern: (?<protocol>https?)://(?<domain>[^/]+)(?<path>/[^?#]*)?(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?
# Input: https://example.com/path/to/page?param=value#section
# Groups: protocol=https, domain=example.com, path=/path/to/page, query=param=value, fragment=section
(?<protocol>https?)://(?<domain>[^/]+)(?<path>/[^?#]*)?(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?

# URL with Subdomain
# Pattern: (?<protocol>https?)://(?<subdomain>[^/.]+)\.(?<domain>[^/]+)(?<path>/.*)
# Input: https://blog.example.com/post/123
# Groups: protocol=https, subdomain=blog, domain=example.com, path=/post/123
(?<protocol>https?)://(?<subdomain>[^/.]+)\.(?<domain>[^/]+)(?<path>/.*)

# URL with Port
# Pattern: (?<protocol>https?)://(?<domain>[^/:]+):(?<port>\d+)(?<path>/.*)
# Input: http://localhost:8080/api/users
# Groups: protocol=http, domain=localhost, port=8080, path=/api/users
(?<protocol>https?)://(?<domain>[^/:]+):(?<port>\d+)(?<path>/.*)

# URL with Auth (rare)
# Pattern: (?<protocol>https?)://(?<user>[^:]+):(?<pass>[^@]+)@(?<domain>[^/]+)
# Input: https://admin:[email protected]
# Groups: protocol=https, user=admin, pass=password, domain=example.com
(?<protocol>https?)://(?<user>[^:]+):(?<pass>[^@]+)@(?<domain>[^/]+)

# Extract Domain Parts
# Pattern: (?<protocol>https?)://(?<subdomain>[^.]+)\.(?<domain>[^.]+)\.(?<tld>[^.]+)
# Input: https://www.example.com
# Groups: protocol=https, subdomain=www, domain=example, tld=com
(?<protocol>https?)://(?<subdomain>[^.]+)\.(?<domain>[^.]+)\.(?<tld>[^.]+)

📝 Email Parsing Patterns regex

🟡 intermediate ⭐⭐⭐

Extract email components (local part, domain, TLD) from email addresses

⏱️ 8 min 🏷️ email, parsing, validation, contact
# Email Parsing with Named Groups
# Extract local part, domain, and TLD from email addresses

# Basic Email Structure
# Pattern: (?<local>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^@]+)
# Input: [email protected]
# Groups: local=user, domain=example, tld=com
(?<local>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^@]+)

# Email with Subdomain
# Pattern: (?<local>[^@]+)@(?<subdomain>[^.]+)\.(?<domain>[^.]+)\.(?<tld>[^.]+)
# Input: [email protected]
# Groups: local=user, subdomain=mail, domain=example, tld=com
(?<local>[^@]+)@(?<subdomain>[^.]+)\.(?<domain>[^.]+)\.(?<tld>[^.]+)

# Email with Plus Tagging
# Pattern: (?<local>[^+]+)\+(?<tag>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^@]+)
# Input: [email protected]
# Groups: local=user, tag=promo, domain=example, tld=com
(?<local>[^+]+)\+(?<tag>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^@]+)

# Country Code TLD
# Pattern: (?<local>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^.]+)\.(?<country>[a-z]{2})
# Input: [email protected]
# Groups: local=user, domain=example, tld=co, country=uk
(?<local>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^.]+)\.(?<country>[a-z]{2})

# Academic Email
# Pattern: (?<local>[^@]+)@(?<department>[^.]+)\.(?<university>[^.]+)\.(?<tld>edu)
# Input: [email protected]
# Groups: local=student, department=cs, university=mit, tld=edu
(?<local>[^@]+)@(?<department>[^.]+)\.(?<university>[^.]+)\.(?<tld>edu)

📝 GPS Coordinates Parsing Patterns regex

🟡 intermediate ⭐⭐⭐

Extract latitude and longitude from GPS coordinate formats

⏱️ 8 min 🏷️ gps, coordinates, location, geography
# GPS Coordinates Parsing with Named Groups
# Extract latitude and longitude from coordinate strings

# Decimal Degrees
# Pattern: (?<lat>-?\d+\.\d+),\s*(?<lon>-?\d+\.\d+)
# Input: 40.7128, -74.0060
# Groups: lat=40.7128, lon=-74.0060
(?<lat>-?\d+\.\d+),\s*(?<lon>-?\d+\.\d+)

# DMS Format (Degrees Minutes Seconds)
# Pattern: (?<lat_deg>\d+)°(?<lat_min>\d+)'(?<lat_sec>\d+(?:\.\d+)?)?" (?<lat_dir>[NS]), (?<lon_deg>\d+)°(?<lon_min>\d+)'(?<lon_sec>\d+(?:\.\d+)?)?" (?<lon_dir>[EW])
# Input: 40°42'55" N, 74°00'21" W
# Groups: lat_deg=40, lat_min=42, lat_sec=55, lat_dir=N, lon_deg=74, lon_min=00, lon_sec=21, lon_dir=W
(?<lat_deg>\d+)°(?<lat_min>\d+)'(?<lat_sec>\d+(?:\.\d+)?)?" (?<lat_dir>[NS]), (?<lon_deg>\d+)°(?<lon_min>\d+)'(?<lon_sec>\d+(?:\.\d+)?)?" (?<lon_dir>[EW])

# Degrees Decimal Minutes
# Pattern: (?<lat_deg>\d+)°(?<lat_min>\d+\.\d+)' (?<lat_dir>[NS]), (?<lon_deg>\d+)°(?<lon_min>\d+\.\d+)' (?<lon_dir>[EW])
# Input: 40°42.917' N, 74°00.350' W
# Groups: lat_deg=40, lat_min=42.917, lat_dir=N, lon_deg=74, lon_min=00.350, lon_dir=W
(?<lat_deg>\d+)°(?<lat_min>\d+\.\d+)' (?<lat_dir>[NS]), (?<lon_deg>\d+)°(?<lon_min>\d+\.\d+)' (?<lon_dir>[EW])

# Geo URI Format
# Pattern: geo:(?<lat>-?\d+\.\d+),(?<lon>-?\d+\.\d+)(?:\?(?<zoom>\d+))?
# Input: geo:40.7128,-74.0060?z=15
# Groups: lat=40.7128, lon=-74.0060, zoom=15
geo:(?<lat>-?\d+\.\d+),(?<lon>-?\d+\.\d+)(?:\?(?<zoom>\d+))?

📝 Product Code Parsing Patterns regex

🟡 intermediate ⭐⭐⭐

Extract product information from SKU, UPC, and product codes

⏱️ 10 min 🏷️ product, sku, inventory, parsing
# Product Code Parsing with Named Groups
# Extract category, SKU, variant from product codes

# Simple SKU
# Pattern: (?<category>[A-Z]{2})-(?<sku>\d{4})-(?<variant>[A-Z]{2})
# Input: EL-1234-LG
# Groups: category=EL, sku=1234, variant=LG
(?<category>[A-Z]{2})-(?<sku>\d{4})-(?<variant>[A-Z]{2})

# UPC-A Barcode
# Pattern: (?<system>\d{1})(?<mfg>\d{5})(?<product>\d{5})(?<check>\d{1})
# Input: 012345678901
# Groups: system=0, mfg=12345, product=67890, check=1
(?<system>\d{1})(?<mfg>\d{5})(?<product>\d{5})(?<check>\d{1})

# ISBN-13
# Pattern: (?<prefix>\d{3})-(?<group>\d{1,5})-(?<publisher>\d{1,7})-(?<title>\d{1,7})-(?<check>\d{1})
# Input: 978-0-306-40615-7
# Groups: prefix=978, group=0, publisher=306, title=40615, check=7
(?<prefix>\d{3})-(?<group>\d{1,5})-(?<publisher>\d{1,7})-(?<title>\d{1,7})-(?<check>\d{1})

# Color-Size Product Code
# Pattern: (?<product>[A-Z]{3})(?<size>XS|S|M|L|XL)(?<color>BL|RD|GR|BK)
# Input: TSHIRTLRDBL
# Groups: product=TSHIRT, size=L, color=RD
(?<product>[A-Z]{3})(?<size>XS|S|M|L|XL)(?<color>BL|RD|GR|BK)

# Hierarchical Product Code
# Pattern: (?<dept>\d{2})\.(?<class>\d{2})\.(?<item>\d{4})-(?<color>\d{2})
# Input: 10.20.1234-56
# Groups: dept=10, class=20, item=1234, color=56
(?<dept>\d{2})\.(?<class>\d{2})\.(?<item>\d{4})-(?<color>\d{2})

📝 File Path Parsing Patterns regex

🟡 intermediate ⭐⭐⭐

Extract directory, filename, and extension from file paths

⏱️ 8 min 🏷️ file, path, filesystem, parsing
# File Path Parsing with Named Groups
# Extract directory, filename, extension from file paths

# Unix Path
# Pattern: (?<dir>/[^/]*)/(?<file>[^/]+)\.(?<ext>[^.]+)
# Input: /home/user/documents/report.pdf
# Groups: dir=/home/user/documents, file=report, ext=pdf
(?<dir>/[^/]*)/(?<file>[^/]+)\.(?<ext>[^.]+)

# Windows Path
# Pattern: (?<drive>[A-Z]:)\\(?<dir>[^\\]+)\\(?<file>[^\\]+)\.(?<ext>[^.]+)
# Input: C:\\Users\\Admin\\Documents\\report.docx
# Groups: drive=C:, dir=Users\Admin\Documents, file=report, ext=docx
(?<drive>[A-Z]:)\\(?<dir>[^\\]+)\\(?<file>[^\\]+)\.(?<ext>[^.]+)

# URL Path
# Pattern: https?://[^/]+(?<path>/[^/]+/)(?<file>[^/]+)\.(?<ext>[^.]+)
# Input: https://example.com/downloads/images/photo.jpg
# Groups: path=/downloads/images/, file=photo, ext=jpg
https?://[^/]+(?<path>/[^/]+/)(?<file>[^/]+)\.(?<ext>[^.]+)

# Hidden File (Unix)
# Pattern: (?<dir>/[^/]*)/(?<hidden>\.(?<file>[^/]+))\.(?<ext>[^.]+)
# Input: /home/user/.bashrc.backup
# Groups: dir=/home/user, hidden=.bashrc, file=bashrc, ext=backup
(?<dir>/[^/]*)/(?<hidden>\.(?<file>[^/]+))\.(?<ext>[^.]+)

# Versioned Filename
# Pattern: (?<file>[^-]+)-(?<version>\d+\.\d+\.\d+)\.(?<ext>[^.]+)
# Input: myapp-2.1.0.tar.gz
# Groups: file=myapp, version=2.1.0, ext=tar.gz
(?<file>[^-]+)-(?<version>\d+\.\d+\.\d+)\.(?<ext>[^.]+)

📝 Semantic Version Parsing Patterns regex

🟡 intermediate ⭐⭐⭐

Parse semantic version strings into major, minor, patch, and pre-release components

⏱️ 10 min 🏷️ version, semver, parsing, release
# Semantic Version Parsing with Named Groups
# Parse major, minor, patch, pre-release, build from version strings

# Basic SemVer
# Pattern: v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)
# Input: v2.1.0
# Groups: major=2, minor=1, patch=0
v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)

# SemVer with Pre-release
# Pattern: v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?
# Input: 2.0.0-alpha.1
# Groups: major=2, minor=0, patch=0, pre=alpha.1
v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?

# SemVer with Build Metadata
# Pattern: v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+))?(?:\+(?<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?
# Input: 1.4.2-beta+exp.sha.5114f85
# Groups: major=1, minor=4, patch=2, pre=beta, build=exp.sha.5114f85
v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+))?(?:\+(?<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?

# Package Version
# Pattern: (?<name>[a-z]+)@(?<version>\d+\.\d+\.\d+)
# Input: [email protected]
# Groups: name=package, version=2.1.0
(?<name>[a-z]+)@(?<version>\d+\.\d+\.\d+)

# Version Range
# Pattern: (?<min>\d+\.\d+\.\d+) - (?<max>\d+\.\d+\.\d+)
# Input: 1.0.0 - 2.0.0
# Groups: min=1.0.0, max=2.0.0
(?<min>\d+\.\d+\.\d+) - (?<max>\d+\.\d+\.\d+)

📝 Log File Parsing Patterns regex

🔴 complex ⭐⭐⭐⭐

Parse server log entries with timestamp, level, message, and metadata

⏱️ 12 min 🏷️ logging, parsing, server, debugging
# Log File Parsing with Named Groups
# Extract timestamp, level, logger, message from log entries

# Apache Common Log Format
# Pattern: (?<ip>\d+\.\d+\.\d+\.\d+) - (?<user>\S+) \[(?<timestamp>[^\]]+)\] "(?<method>\w+) (?<path>\S+) (?<protocol>\S+)" (?<status>\d+) (?<size>\d+)
# Input: 192.168.1.1 - - [16/Jan/2025:14:30:45 +0000] "GET /index.html HTTP/1.1" 200 1234
# Groups: ip=192.168.1.1, user=-, timestamp=16/Jan/2025:14:30:45 +0000, method=GET, path=/index.html, protocol=HTTP/1.1, status=200, size=1234
(?<ip>\d+\.\d+\.\d+\.\d+) - (?<user>\S+) \[(?<timestamp>[^\]]+)\] "(?<method>\w+) (?<path>\S+) (?<protocol>\S+)" (?<status>\d+) (?<size>\d+)

# Application Log Format
# Pattern: \[(?<timestamp>[^\]]+)\] (?<level>\w+) (?<logger>\S+) - (?<message>.*)
# Input: [2025-01-16 14:30:45] INFO com.example.Service - Request processed successfully
# Groups: timestamp=2025-01-16 14:30:45, level=INFO, logger=com.example.Service, message=Request processed successfully
\[(?<timestamp>[^\]]+)\] (?<level>\w+) (?<logger>\S+) - (?<message>.*)

# Error Log with Exception
# Pattern: \[(?<timestamp>[^\]]+)\] (?<level>ERROR) (?<logger>\S+) - (?<message>[^\[]+) \[(?<exception>[^\]]+)\]
# Input: [2025-01-16 14:30:45] ERROR com.example.Service - Database connection failed [SQLException: Connection timeout]
# Groups: timestamp=2025-01-16 14:30:45, level=ERROR, logger=com.example.Service, message=Database connection failed, exception=SQLException: Connection timeout
\[(?<timestamp>[^\]]+)\] (?<level>ERROR) (?<logger>\S+) - (?<message>[^\[]+) \[(?<exception>[^\]]+)\]

# Nginx Log Format
# Pattern: (?<ip>[^ ]*) - (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\w+) (?<path>[^ ]*) (?<protocol>[^"]*)" (?<status>\d+) (?<size>\d+) "(?<referrer>[^"]*)" "(?<ua>[^"]*)"
# Input: 127.0.0.1 - - [16/Jan/2025:14:30:45 +0000] "GET /api/users HTTP/1.1" 200 1234 "-" "Mozilla/5.0"
# Groups: ip=127.0.0.1, user=-, time=16/Jan/2025:14:30:45 +0000, method=GET, path=/api/users, protocol=HTTP/1.1, status=200, size=1234, referrer=-, ua=Mozilla/5.0
(?<ip>[^ ]*) - (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\w+) (?<path>[^ ]*) (?<protocol>[^"]*)" (?<status>\d+) (?<size>\d+) "(?<referrer>[^"]*)" "(?<ua>[^"]*)"

📝 Person Name Parsing Patterns regex

🔴 complex ⭐⭐⭐⭐

Parse person names into title, first name, middle name, last name, and suffix

⏱️ 12 min 🏷️ name, parsing, personal, formatting
# Person Name Parsing with Named Groups
# Parse names into title, first, middle, last, suffix

# Full Name with Title
# Pattern: (?<title>Mr|Mrs|Ms|Dr|Prof)\.? (?<first>[A-Z][a-z]+) (?<last>[A-Z][a-z]+)
# Input: Dr. John Smith
# Groups: title=Dr, first=John, last=Smith
(?<title>Mr|Mrs|Ms|Dr|Prof)\.? (?<first>[A-Z][a-z]+) (?<last>[A-Z][a-z]+)

# Name with Middle Initial
# Pattern: (?<first>[A-Z][a-z]+) (?<middle>[A-Z])\. (?<last>[A-Z][a-z]+)
# Input: John A. Smith
# Groups: first=John, middle=A, last=Smith
(?<first>[A-Z][a-z]+) (?<middle>[A-Z])\. (?<last>[A-Z][a-z]+)

# Name with Suffix
# Pattern: (?<first>[A-Z][a-z]+) (?<last>[A-Z][a-z]+) (?<suffix>Jr|Sr|II|III|IV)
# Input: Robert Smith Jr
# Groups: first=Robert, last=Smith, suffix=Jr
(?<first>[A-Z][a-z]+) (?<last>[A-Z][a-z]+) (?<suffix>Jr|Sr|II|III|IV)

# Full Name with Middle Name
# Pattern: (?<first>[A-Z][a-z]+) (?<middle>[A-Z][a-z]+) (?<last>[A-Z][a-z]+)
# Input: William Henry Harrison
# Groups: first=William, middle=Henry, last=Harrison
(?<first>[A-Z][a-z]+) (?<middle>[A-Z][a-z]+) (?<last>[A-Z][a-z]+)

# Last, First Format
# Pattern: (?<last>[A-Z][a-z]+), (?<first>[A-Z][a-z]+)(?: (?<middle>[A-Z][a-z]+))?
# Input: Smith, John Henry
# Groups: last=Smith, first=John, middle=Henry
(?<last>[A-Z][a-z]+), (?<first>[A-Z][a-z]+)(?: (?<middle>[A-Z][a-z]+))?

📝 Credit Card Parsing Patterns regex

🔴 complex ⭐⭐⭐⭐

Extract card components (BIN, account, check digit) from credit card numbers

⏱️ 10 min 🏷️ payment, credit card, financial, validation
# Credit Card Parsing with Named Groups
# Extract BIN, account number, and check digit from card numbers

# Visa Card (16 digits)
# Pattern: (?<network>4)(?<bin>\d{4})(?<account>\d{8})(?<check>\d{4})
# Input: 4532015112830366
# Groups: network=4, bin=4532, account=01511283, check=0366
(?<network>4)(?<bin>\d{4})(?<account>\d{8})(?<check>\d{4})

# Mastercard (16 digits)
# Pattern: (?<network>5[1-5])(?<bin>\d{3})(?<account>\d{9})(?<check>\d{3})
# Input: 5555555555554444
# Groups: network=55, bin=555, account=555555555, check=444
(?<network>5[1-5])(?<bin>\d{3})(?<account>\d{9})(?<check>\d{3})

# Amex (15 digits)
# Pattern: (?<network>3[47])(?<bin>\d{4})(?<account>\d{7})(?<check>\d{4})
# Input: 378282246310005
# Groups: network=37, bin=8282, account=2463100, check=0005
(?<network>3[47])(?<bin>\d{4})(?<account>\d{7})(?<check>\d{4})

# Formatted Card Number
# Pattern: (?<network>\d{4})-(?<bin>\d{4})-(?<account>\d{4})-(?<check>\d{4})
# Input: 4532-0151-1283-0366
# Groups: network=4532, bin=0151, account=1283, check=0366
(?<network>\d{4})-(?<bin>\d{4})-(?<account>\d{4})-(?<check>\d{4})

# Card with Expiry and CVV
# Pattern: (?<number>\d{16}) Exp: (?<expiry>\d{2}/\d{2}) CVV: (?<cvv>\d{3,4})
# Input: 4532015112830366 Exp: 12/25 CVV: 123
# Groups: number=4532015112830366, expiry=12/25, cvv=123
(?<number>\d{16}) Exp: (?<expiry>\d{2}/\d{2}) CVV: (?<cvv>\d{3,4})