Regular expressions — or regex — are one of those tools that seem intimidating at first but become incredibly powerful once you get the hang of them. Whether you're validating form inputs, parsing log files, or searching through code, regex can save you hours of manual work.
In this guide, you'll learn the essentials: what regex is, the core syntax you need to know, and how to test your patterns online without installing anything.
What Is a Regular Expression?
A regular expression is a sequence of characters that defines a search pattern. Think of it as a super-powered "Find" function — instead of searching for a fixed word, you describe the shape of what you're looking for.
For example, instead of searching for "2025-05-15" specifically, you could write a pattern that matches any date in YYYY-MM-DD format. That's the power of regex.
Regex is supported in virtually every programming language — JavaScript, Python, Go, Java, Ruby — and in most code editors, terminal tools, and databases.
Quick Reference: Core Regex Syntax
Here's a cheat sheet of the most common regex building blocks:
Character Classes
| Pattern | Matches |
|---|---|
. | Any single character (except newline) |
\d | Any digit (0–9) |
\w | Any word character (letters, digits, underscore) |
\s | Any whitespace (space, tab, newline) |
[abc] | Exactly a, b, or c |
[a-z] | Any lowercase letter |
[^abc] | Anything except a, b, or c |
Quantifiers
| Pattern | Meaning |
|---|---|
* | 0 or more times |
+ | 1 or more times |
? | 0 or 1 time (optional) |
{3} | Exactly 3 times |
{2,5} | Between 2 and 5 times |
Anchors
| Pattern | Meaning |
|---|---|
^ | Start of the string |
$ | End of the string |
\b | Word boundary |
Groups & Alternation
| Pattern | Meaning |
|---|---|
(abc) | Capture group |
a|b | Match a or b |
3 Practical Regex Examples
1. Email Address Validation
^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$
How it works:
^[\w.-]+— starts with one or more word characters, dots, or hyphens (the local part)@— literal at-sign[\w.-]+— domain name\.[a-zA-Z]{2,}$— a dot followed by a TLD of at least 2 letters
This matches user@example.com but rejects @missinglocal.com or nodomain.
2. URL Detection
https?:\/\/[\w.-]+(\/[\w./?=%&-]*)?
How it works:
https?— matches bothhttpandhttps:\/\/— literal://[\w.-]+— the domain(\/[\w./?=%&-]*)?— optional path and query string
This matches https://ujiffy.dev/tools/regex-tester and http://example.com.
3. Date Format (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
How it works:
\d{4}— exactly 4 digits for the year(0[1-9]|1[0-2])— month 01–12(0[1-9]|[12]\d|3[01])— day 01–31
This rejects invalid months like 13 and days like 00.
Why Use an Online Regex Tester?
Writing regex in your code editor and then running the whole program just to test a pattern is slow and frustrating. An online regex tester lets you:
- See matches highlighted in real-time as you type your pattern
- Iterate fast — tweak a character, see the result immediately
- Test edge cases by pasting sample data directly into the tool
- View capture groups to understand what each part of your pattern extracts
- Work without setup — no IDE, no language runtime, no install
This is especially helpful when you're learning. Instead of guessing why your pattern doesn't work, you can visually debug it step by step.
Tips for Writing Better Regex
- Start simple and build up. Don't write the full pattern at once — match one part, verify it, then extend.
- Use anchors when you mean to match the whole string.
\d+matches digits anywhere;^\d+$only matches strings that are entirely digits. - Escape special characters. Characters like
.,*,+,(,)have special meanings. Use a backslash to match them literally:\.matches a real dot. - Use groups for extraction. Wrapping part of your pattern in
()lets you extract that piece separately — useful for pulling out domain names, area codes, etc.
Start Testing Your Patterns Now
The best way to learn regex is to experiment. Don't memorize everything — just understand the concepts and look up the syntax as needed. An online tester makes this painless.
Paste in your test string, write your pattern, and watch the matches light up. No sign-up, no installation — just results.