The Ultimate Guide to Regular Expressions (Regex): Syntax, Testing, and Cheat Sheet
Master regular expressions from scratch. Learn metacharacters, character classes, lookaheads, regex flags, and how to test patterns safely in your browser.
### The Double-Edged Sword of Regular Expressions Computer scientist Jamie Zawinski famously quipped: *"Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems."* Regular Expressions (Regex) are undeniably one of the most potent weapons in a software engineer’s toolkit. A concise 20-character regex string can validate complex email structures, scrub telephone numbers across millions of customer database rows, extract server IP addresses from gigabytes of Nginx access logs, or sanitize user input against cross-site scripting (XSS) attacks. However, because regex syntax is dense and cryptic, a tiny misplaced character—such as confusing greedy quantifiers (`.*`) with lazy quantifiers (`.*?`), or forgetting anchor boundaries (`^` and `
Frequently Asked Questions
What is the difference between greedy and lazy matching in regex?
Greedy matching matches as much text as possible. Lazy matching matches as little text as possible to satisfy the expression.
What is a Regular Expression Denial of Service (ReDoS) attack?
ReDoS occurs when an inefficient regex with nested quantifiers (like (a+)+) is evaluated against a malformed string, causing exponential backtracking that freezes the CPU.
Can I test regular expressions in multiple programming language flavors?
Toolkitly uses ECMAScript (JavaScript) regex rules, which share 95% syntax parity with Python, PCRE (PHP), and Java.
Are my test strings uploaded to a server?
No. All regex evaluation executes locally inside your web browser sandbox.