Works on this device. File exports run online.
Regex Tester & Builder
Type a pattern and some text: matches are highlighted as you type, with their groups and positions, and every part of the pattern is explained. Build a pattern from examples or pick a common one, copy it for your language, or run it in real Python or Java to see what they find.
Test a regular expression
After replacing
What the pattern means
Build a pattern
Other languages
How to test a regex
- Type the pattern without slashes, and tick the flags (g all matches, i ignore case, m lines, s dot matches line breaks, u Unicode).
- Paste the text to search. Matches are marked and listed with their groups.
- Tick Replace to see the text after replacing ($1 or $<name> insert groups).
One pattern, several languages
- The tester uses JavaScript’s engine. Most patterns mean the same in Python, Java, PHP (PCRE), C# and Go; the differences that matter (named groups, look-behind, back-references, \d with Unicode, $ before a final line break) are listed for your pattern.
- The code box writes the pattern for each language, with its flags and the named-group syntax converted for Python.
- Go’s RE2 engine has no look-around or back-references: patterns that use them do not work there.
Run it in Python or Java
- Under Run in Python or Java, choose Python’s re, the Python regex package or Java’s java.util.regex, and what to do: find all matches, check the whole text, replace or split. Select Run.
- The pattern, flags (i, m, s), text and replacement of the tester are used. Syntax that only JavaScript has is written the engine’s way first: named groups become (?P<name>…) for Python’s re, and a replacement $1 or $<name> becomes \1 or \g<name> for Python and $1 or ${name} for Java. The result says exactly what was run.
- Python counts positions in characters. Java counts UTF-16 code units, as its own Matcher does, so an emoji counts as two. Line and column always count characters.
- The results can be downloaded as a CSV table of the matches, the replaced text and a JSON file with every group.
Time limit
- Some patterns backtrack so much that they would run for hours on a short text (catastrophic backtracking, for example (a+)+$ or (.*?,){11}P). This is also how a regex can be used to slow a server down (ReDoS).
- The tester in your browser stops after 2 seconds. On the server each run stops after the time limit you choose (0.1 to 5 seconds, 1 second if you do not choose) and the page says that the pattern was stopped. The engine runs in a separate process that is ended at the limit.
- Java 9 and later remember some failed repeats and answer (a+)+$ at once, while Python backtracks; patterns like (.*?,){11}P are slow in both. Fix such patterns with exclusive repeats ([^,]*, instead of .*?,) or atomic groups and possessive repeats where the engine has them.
Building a pattern
Type a few examples, one per line: when they share a shape (digits, letters and the same punctuation in the same places), the pattern uses classes and lengths; otherwise it lists the examples. Check it against counter-examples. The common patterns state their limits; an e-mail pattern can only check the form of an address.