Enter a regular expression and test text to see real-time match results with a railroad diagram visualization of the regex syntax, helping you understand and debug regular expressions
The Regex Tester is an interactive tool for developing and debugging regular expressions. Enter a regex pattern and test text, and the tool returns all match results in real time, including matched text, start/end positions, and detailed capture group information.
A standout feature of this tool is the Railroad Diagram visualization. The railroad diagram graphically displays the syntactic structure and execution flow of a regular expression, turning abstract regex syntax into an intuitive path diagram that helps you quickly understand even complex regex patterns.
All standard regex flags are supported: g (global), i (case-insensitive), m (multiline), s (dotAll), and u (unicode).
A regular expression (regex) is a metalanguage for describing string matching patterns, rooted in the formal language theory of regular languages and finite automata. The JavaScript engine in browsers has a built-in high-performance regex engine based on backtracking, supporting advanced features like lookahead/lookbehind assertions and named capture groups.
This tool's frontend implementation has two parts: the matching engine uses the browser's native RegExp API and String.prototype.matchAll() to retrieve all global match results; the visualization component uses the regulex open-source library, which parses a regex into an Abstract Syntax Tree (AST) and renders it as an SVG railroad diagram. Each syntactic node of the regex—literals, character classes, quantifiers, groups, and alternation branches—is displayed as a graphical track segment.
. * + ? [ ] ( ) { } ^ $ | \—must be escaped with a backslash \ to match them literally. For example, to match a literal period, write \. rather than ..g (global) flag enabled, the tool returns all matches in the text; without it, only the first match is returned. If you need to extract every occurrence of a pattern (e.g., all email addresses), check the g flag.|), loops represent quantifiers (* + ?), and boxes represent character classes ([abc]). Following any complete path from left to right corresponds to one match sequence of the regex.Scenario: Test a regex for extracting phone numbers.
\d{3}-\d{3}-\d{4}g flag (global matching)Contact: 555-123-4567, Office: 555-987-6543\d{3} quantifier structureScenario: Test date matching with capture groups.
(\d{4})-(\d{2})-(\d{2})Dates: 2024-01-15 and 2025-12-31g and observe the capture group column showing $1 (year), $2 (month), $3 (day)Regular expressions are widely used in text processing and data extraction. In development, regex often works alongside URL Decoder and URL Encoder for parsing and validating URL parameters. The Text Diff tool helps compare text before and after regex replacements.
For multi-line text processing, Line Sorter pairs well with regex for complex data wrangling. Understanding character encoding also helps write more precise regex—see ASCII Lookup and Base Converter.