Command Palette
Search for a command to run...
Regular Expression Search Guide
Harness the power of regular expressions for advanced pattern matching and precise data discovery on LeakZero. Regular expressions represent the pinnacle of pattern matching technology, offering unparalleled precision and flexibility in data discovery operations.
What are Regular Expressions?
Regular expressions are a formal language for describing search patterns using a standardized syntax. Originally developed in theoretical computer science and popularized by Unix systems, regex has become the gold standard for pattern matching across cybersecurity, data analysis, and software development industries.
In the context of breach investigation, regular expressions enable you to:
- Define precise character sequences and variations
- Specify complex structural patterns in email addresses and usernames
- Implement conditional matching logic
- Extract specific data segments from larger datasets
- Validate and identify formatted data types (phone numbers, credit cards, etc.)
Fundamental Regex Components
Basic Character Classes:
Custom Character Classes:
Precise Quantifiers:
Common Quantifiers:
Advanced Regex Patterns for Breach Investigation
Standard Email Validation:
Corporate Email Patterns:
Matches: [email protected]
Administrative Account Detection:
Service Account Identification:
Alphanumeric with Numbers:
Matches: user123, admin1, test99
Corporate Username Standards:
Matches: j.doe, a.smith123, m.johnson
Temporary Account Patterns:
Matches: temp2023, test_user2024
Subdomain Extraction:
Top-Level Domain Variations:
Free Email Provider Detection:
Strategic Regex Applications
C-Suite Email Detection:
Executive Name Variations:
Board Member Identification:
System Administrator Accounts:
Development Environment Detection:
Backup System Identification:
GDPR-Relevant Personal Data:
HIPAA Healthcare Domains:
Financial Services Detection:
APT Campaign Patterns:
Botnet Command Structure:
Phishing Infrastructure:
Performance Optimization for Regex
Optimized vs. Inefficient Patterns:
Best Practices:
- Anchor Patterns: Use ^ and $ to prevent unnecessary backtracking
- Specific Quantifiers: Use {n,m} instead of * when possible
- Non-Capturing Groups: Use (?:...) when you don't need to capture content
- Atomic Groups: Use (?>...) to prevent backtracking where appropriate
Common Regex Patterns for Cybersecurity
Credit Card Numbers:
Social Security Numbers:
Phone Numbers:
IP Addresses:
Suspicious File Extensions:
Command and Control Domains:
Base64 Encoded Strings:
DNS Tunneling Detection:
Advanced Techniques
Positive Lookahead (?=...):
Matches "admin" only if followed by "@company.com"
Negative Lookahead (?!...):
Matches "user" only if NOT followed by "123"
Positive Lookbehind (?<=...):
Matches "@company.com" only if preceded by "admin"
Negative Lookbehind (?<!...):
Matches "@company.com" only if NOT preceded by "test"
If-Then-Else Logic:
Matches either "administrator@..." or "user@..."
Complex Conditional Matching:
Further Reading and Resources
- "Mastering Regular Expressions" by Jeffrey Friedl: The definitive guide to regex theory and practice
- Mozilla Developer Network (MDN): Comprehensive regex documentation and examples
- Regular-Expressions.info: Extensive tutorials and reference materials
- RegexOne Interactive Tutorial: Hands-on learning platform
- SANS Digital Forensics: Regex applications in incident response
- NIST Special Publication 800-86: Guide to integrating forensic techniques
- MITRE ATT&CK: Reconnaissance and collection technique documentation
- OWASP Testing Guide: Security testing with pattern matching