What is Regex?
A Regular Expression (Regex) is a sequence of characters that specifies a search pattern. It is widely used for string matching, validation, and data extraction in programming languages like JavaScript, Python, and PHP.
This tool runs entirely in your browser. No data is sent to any server. It uses the standard JavaScript regex engine.
Cheatsheet
| Char | Description | Example |
|---|---|---|
| ^ | Start of string | ^A |
| $ | End of string | end$ |
| * | 0 or more times | bo* |
| + | 1 or more times | bo+ |
| ? | 0 or 1 time | e?le |
| . | Any character (except newline) | .n |
| \d | Digit [0-9] | \d+ |
| \w | Word char [A-Za-z0-9_] | \w+ |
| \s | Whitespace | \s |
| [abc] | Character set | [aeiou] |
FAQ
What do flags g, i, m mean?
- g (Global): Find all matches, not just the first one.
- i (Insensitive): Case-insensitive matching.
- m (Multiline): ^ and $ match start/end of line.
What is Greedy vs Non-Greedy?
a.*b matches the longest possible string. Adding
? (e.g., a.*?b) makes it "non-greedy" (lazy), matching the
shortest
possible string.
How to match special characters (like . * ?)?
\. For example, use \. to match a dot, and \? for a
question mark.
How to match an email address?
^[\w\.-]+@[\w\.-]+\.\w+$. Note that this is for
demonstration; production-grade email validation can be much more complex.
What are Lookarounds?
(?=foo) (Lookahead)
asserts that what follows is "foo". (?<=foo) (Lookbehind) asserts that what
precedes is "foo".
How to key match numbers only?
\d to match any digit (0-9). Use \d+ to match one or more
digits.
To match a specific length, use \d{n}.
How to match whitespace?
\s to match any whitespace character including spaces, tabs, and line
breaks.
Use \s+ for consecutive whitespace.
Common Regex Flags?
g, i, and m, there is s
(dotAll,
lets . match newlines) and u (Unicode support).
More Free Tools
JSON Formatter
Validate, format, and minify JSON data. Fix common errors automatically.
Diff Checker
Compare two text blocks and highlight differences side-by-side.
UUID Generator
Generate Version 1 and 4 UUIDs (GUIDs) instantly for your applications.
Base64 Converter
Encode and decode text or images to Base64 format online.
SQL Formatter
Beautify and format complex SQL queries for MySQL, PostgreSQL, and more.
Keycode Info
Identify JavaScript key codes, values, and modifiers by pressing any key.