You don't need to be a regular expression master to be a great developer. You just need to know where to find the right pattern when you need it.
We have compiled the 25 most common, production-ready regex patterns that every developer will eventually need. Whether you are validating user input, parsing massive server logs, or building a web scraper, bookmark this page so you never have to write these from scratch again.
You can copy and test any of these patterns instantly using our free Regex Tester.
Data Validation Patterns
When building web forms, these patterns ensure the data entering your database is clean and structured.
1. Standard Email Address
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
2. Strong Password (8+ chars, 1 uppercase, 1 number, 1 special)
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
3. Username (Alphanumeric, 3-16 chars)
^[a-zA-Z0-9_-]{3,16}$
4. Credit Card (Major Providers)
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9][0-9])[0-9]{12})$
5. E.164 International Phone Number
^\+[1-9]\d{1,14}$
6. US ZIP Code (5 or 9 digits)
^\d{5}(?:[-\s]\d{4})?$
Web & Network Parsing
If you are dealing with networking code, IP routing, or web scraping, these patterns are essential.
7. HTTP/HTTPS URL
^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$
8. IPv4 Address
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
9. IPv6 Address (Basic)
^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$
10. MAC Address
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$
11. Extract Domain from URL
^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)
12. HTML Tag Extraction (e.g., <div>)
<\/?[\w\s="/.':;#-\/\?]+>
13. Extract href links from anchor tags
<a\s+(?:[^>]*?\s+)?href=(["'])(.*?)\1
Dates, Times, and Numbers
Parsing logs or managing localized dates requires strict numerical matching.
14. Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
15. Date (DD/MM/YYYY)
^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$
16. Time (24-Hour Format)
^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$
17. Time (12-Hour Format with AM/PM)
^(0?[1-9]|1[0-2]):[0-5][0-9]\s?(AM|PM|am|pm)$
18. Currency (US Dollar, handles commas and cents)
^\$?\d+(,\d{3})*(\.\d{2})?$
19. Integer (Positive or Negative)
^-?\d+$
20. Float / Decimal Number
^-?\d*\.\d+$
String and Text Manipulation
These patterns are perfect for cleaning up user input or formatting strings before rendering them to the UI.
21. Hex Color Code (3 or 6 chars, optional #)
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
22. File Extension Extraction (.jpg, .pdf)
^.*\.(jpg|jpeg|png|gif|pdf|docx)$
23. Find Duplicate Words in a String
\b(\w+)\s+\1\b
24. Match Blank / Empty Strings (Only whitespace)
^\s*$
25. Extract Text Between Two Quotes
(["'])(?:(?=(\\?))\2.)*?\1
Frequently Asked Questions (FAQ)
Are these regex patterns language-agnostic?
Yes, the vast majority of these patterns use PCRE (Perl Compatible Regular Expressions) syntax, which works identically across JavaScript, Python, PHP, Ruby, and Java.
How do I use these patterns in my code?
It depends on your language. In JavaScript, you wrap the pattern in forward slashes: /pattern/. In Python, you use a raw string inside the re module: re.search(r"pattern", string).
Why does my regex match the entire string instead of just the word?
If your regex is matching everything to the end of the line, you are likely using a "greedy" quantifier like * or +. To make it "lazy" (so it stops at the first valid endpoint), append a question mark: *? or +?.
Do I need the ^ and $ anchors?
If you are validating that a string is exactly an email address, yes, you must use ^ (start) and $ (end). If you are trying to extract an email address out of a massive block of text, you should remove the anchors.
How can I debug a broken regex pattern?
Never debug regular expressions directly in your application code. Paste your pattern and a few test strings into the free FluxToolkit Regex Tester to visually highlight capture groups and identify errors instantly.





