Regular Expression Patterns
The re module provides a comprehensive collection of pre-defined regular expressions for common data validation tasks. These patterns are designed to handle various validation scenarios across different fields, making input validation simpler and more reliable.
Categories
The module includes patterns for the following categories:
Username Validation
Password Validation
Email Validation
Phone Number Validation
Zip Code Validation
Address Validation
Credit Card Validation
IP Address Validation
Date Validation
URL Validation
Username Patterns
Password Patterns
Credit Card Patterns
URL Patterns
- true.re.URL_WITH_PORT: str
Matches URLs that include a port number.
Example:
“http://www.example.com:8080” matches
“http://www.example.com” doesn’t match (no port)
- true.re.URL_WITH_SUBDOMAIN: str
Matches URLs that include subdomains.
Example:
“http://sub.example.com” matches
“https://sub.sub2.example.com” matches
“not-a-url” doesn’t match
Usage
To use these patterns in your code:
from true.re import USERNAME_ONLY_LETTERS_MIN_3
import re
# Validate a username
username = "John"
if re.match(USERNAME_ONLY_LETTERS_MIN_3, username):
print("Valid username!")
else:
print("Invalid username!")