Skip to content
Categories
Regex Tester
Test a regular expression pattern and check the matching results.
Overview
- Runs a regular expression pattern against actual test text and shows the matched positions and capture groups.
- Since you can tweak the pattern little by little and immediately see whether it matches as intended, this is well suited to writing and debugging regular expressions.
- Uses JavaScript's regular expression engine (RegExp) directly, so it behaves the same as the regex you'd use in actual code.
Usage
- Enter a regular expression pattern and flags (such as g, i, m).
- Enter the text you want to test against in the text area.
- Click the "Test" button to see a list of matched positions and capture groups.
Example
Input
Pattern: \d{3}-\d{4} / Flags: g / Text: 090-1234 / 080-5678Output
1: 090-1234 (index: 0) 2: 080-5678 (index: 11)
Use Cases
- Building a validation regex (such as an email or phone number format check) while trying it against real data
- Verifying that a regex already used in code behaves as intended, using test cases that include edge cases
- Iterating on a regex to extract lines matching a specific pattern from logs, trying it against real log text
- Building a regex to detect or replace mixed line break codes (\r\n, \n, \r) in text, testing it against real text
FAQ
Is there a limit on the number of matches?
Yes. To prevent rendering delays, up to 1000 matches are displayed.
What flags can I specify?
You can specify flags supported by JavaScript regular expressions, such as g, i, m, s, u, and y.
What happens if I enter an invalid regular expression?
An error message "The regular expression is invalid." is displayed along with the specific error details.
How do I handle line break codes (such as \r\n, \n) with a regex?
Include a line break in the test text, then specify \r\n, \n, or \r in the pattern to check for a match. To detect text with mixed line break codes, a pattern that lists the candidates, such as \r\n|\r|\n, works well.
Notes
- Up to 1000 matches are displayed. If there are more, only the first 1000 are shown.
- You can specify flags supported by JavaScript regular expressions, such as g, i, m, s, u, and y. Without the g flag, only the first match is targeted.
- If the entered regular expression is syntactically invalid, an error message with specific details is displayed.
Related Tools
Format HTML to make it easier to read.
Format CSS to make it easier to read.
Format JavaScript to make it easier to read.
Format TypeScript to make it easier to read.