Guide · Developers
How Do I Test a Regex Pattern Online?
A regular expression (regex) is a compact search pattern for text. Testing it means typing sample strings, watching what matches, and fixing edge cases before you ship validation or log parsers. You can do that instantly in the browser with ConvertPal’s free Regex Tester— live highlights, flags, and match lists without installing anything.
What Is a Regular Expression (Regex)?
Regex is a tiny language for describing text shape: which characters may appear, how many times, and in what order. Engines like JavaScript’s RegExp compile your pattern, scan the input, and report matches, captures, and indices.
Teams use regex for validation (emails, IDs), search in editors and CLIs, find-and-replace in large refactors, and light parsing when a full parser would be heavy—always pair tricky inputs with normal tests because regex can be subtle with Unicode and newlines.
Regex Cheat Sheet — Common Patterns
These tokens work in JavaScript-style regex; exact behavior can vary slightly across engines.
| Pattern | What it matches | Example |
|---|---|---|
| \d | Any digit (0–9) | ID\d+ → ID42 |
| \w | Word character (letter, digit, underscore) | \w+ → foo_9 |
| \s | Whitespace (space, tab, newline) | a\sb → a b |
| ^ | Start of line (or string, without m) | ^https → https only at start |
| $ | End of line (or string, without m) | \.pdf$ → ends with .pdf |
| * | Zero or more of the previous token | ab*c → ac, abc, abbc |
| + | One or more of the previous token | ab+c → abc, abbc |
| ? | Zero or one (makes + and * lazy when appended) | colou?r → color, colour |
| . | Any single character except newline (unless dotAll) | a.c → aac, a1c |
| [] | One character from a set | [aeiou] → one vowel |
| () | Capturing group (also precedence) | (https)?:// |
| {n,m} | Between n and m repetitions | \d{3,5} → 3 to 5 digits |
| | | Alternation (this OR that) | cat|dog |
Common Regex Patterns You Can Copy
Treat these as starting points—tighten rules for production (especially email and URLs).
Email (practical, not RFC-complete)
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Good for quick forms; tighten for internationalized email or strict RFC rules.
URL (http/https, common shape)
^https?://[^\s/$.?#].[^\s]*$
Catches typical URLs; validate with a real URL parser for security-sensitive flows.
US phone (digits with optional separators)
^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$Accepts many US formats; strip to digits in code if you store E.164.
IPv4 address
^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$Validates dotted quads; does not check reserved ranges.
Date YYYY-MM-DD
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$Checks shape, not calendar validity (e.g. Feb 30 still matches shape).
Hex color (#RGB or #RRGGBB)
^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$Matches #fff and #ffffff; extend if you allow #RRGGBBAA.
US ZIP (5 or ZIP+4)
^\d{5}(-\d{4})?$Five digits optional hyphen plus four extension.
UK postcode (common outward + inward)
^[A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2}$Broad pattern; Royal Mail rules are stricter—use for light validation only.
Understanding Regex Flags
Flags change how the engine reads your pattern. In JavaScript they appear after the closing slash or in a constructor string.
| Flag | Name | What it does |
|---|---|---|
| g | global | Find all matches in the string, not just the first. |
| i | ignoreCase | Treat letters as case-insensitive (A equals a). |
| m | multiline | Make ^ and $ match line starts/ends, not only whole string. |
| s | dotAll | Let . match newline characters (ES2018+). |
| u | unicode | Treat pattern as Unicode code points; enables \u{...} escapes. |
Test Your Regex Pattern Now
The Regex Tester runs entirely in your browser: paste a pattern, toggle g, i, m, s, and u, type sample text, and see match highlights plus capture groups—ideal before you paste the same regex into production code.
Frequently Asked Questions
- What does the g flag do in regex?
- The
g(global) flag tells the engine to find every match in the string instead of stopping after the first hit. That matters forreplacewith a function,matchAll, and loops that advance thelastIndexpointer. Withoutg, many APIs only surface the first occurrence—which is correct for some checks but surprising when you expect “replace all.” - How do I match any character in regex?
- The dot
.matches almost any single character except a newline in default JavaScript mode. With thes(dotAll) flag, dot also matches line breaks. If you need true “any character” without dotAll, use a negated empty class trick sparingly or match explicit classes—dot is convenient but easy to misuse on multiline logs. - What is the difference between * and + in regex?
*means “zero or more” of the preceding token, while+means “one or more.” Soab*callowsacwith nob, butab+crequires at least oneb. Both are greedy by default; append?to make them lazy when you need the shortest match.- How do I make a regex case insensitive?
- In JavaScript, add the
iflag:/hello/imatches HELLO or HeLLo. In editors or other engines the syntax differs (sometimes(?i)inline), but the idea is the same: case folding for letters while leaving digits and symbols unchanged. Combineiwithgwhen you need all case-insensitive hits. - How do I test if a string is a valid email with regex?
- Use a conservative pattern anchored to the whole string, then test against samples in the Regex Tester—try plus-addressing, subdomains, and punycode domains. Remember: email validation is famously nuanced; regex can reject valid international addresses or accept unsafe strings. For signups, combine a practical regex with DNS or mailbox checks where risk warrants it, and never rely on regex alone for security boundaries.
