
Regex in 10 Minutes: The Patterns You'll Actually Use
Skip the academic textbook. These six regex patterns cover 90% of real-world string matching.
/^[^@\s]+@[^@\s]+\.[^@\s]+$/ — not RFC-perfect, but catches 99.9% of real emails and rejects obvious junk.
Do not try to write a fully RFC-compliant email regex. It is 6,000+ characters long and you will never need it.
URL
/^https?:\/\/[^\s/$.?#].[^\s]*$/ — matches http and https URLs with a host and optional path.
For full validation, use the URL constructor in JavaScript: new URL(input) throws on invalid URLs.
Whitespace and trimming
/\s+/g matches any run of whitespace. Combine with .replace() to collapse multiple spaces into one.
/^\s+|\s+$/g trims leading and trailing whitespace, but String.prototype.trim() is faster and more readable.
Tester workflow
Always test regex in a tester (we ship one) before pasting into production code. Use real sample inputs, including edge cases.
Test for false positives as much as for matches. A regex that matches too much is worse than one that matches too little.
Related articles
Rahul Kapoor writes for WebToolCenter on SEO, AI, and productivity. Every article is researched, tested with real tools, and updated as best practices evolve.
More about our team →Discussion (0)
Sign in to join the conversation.


