Regex Tester

/ /

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?
Regex is "greedy" by default. 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 . * ?)?
These are meta-characters. To match them literally, you need to escape them with a backslash \. For example, use \. to match a dot, and \? for a question mark.
How to match an email address?
A simple valid pattern is: ^[\w\.-]+@[\w\.-]+\.\w+$. Note that this is for demonstration; production-grade email validation can be much more complex.
What are Lookarounds?
Lookarounds match a position without consuming characters. (?=foo) (Lookahead) asserts that what follows is "foo". (?<=foo) (Lookbehind) asserts that what precedes is "foo".
How to key match numbers only?
Use \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?
Use \s to match any whitespace character including spaces, tabs, and line breaks. Use \s+ for consecutive whitespace.
Common Regex Flags?
Aside from g, i, and m, there is s (dotAll, lets . match newlines) and u (Unicode support).

More Free Tools