Regex Tester

By Seagit ✨

Test and debug regular expressions with real-time feedback and highlighted matches

Enter pattern without slashes

g: global · i: ignore case · m: multiline · s: dotAll · u: unicode · y: sticky

What Is a Regex Tester?

A regex tester is an interactive tool that allows developers and technical professionals to write, test, and debug regular expressions in real time. Regular expressions (often abbreviated as regex, regexp, or RE) are sequences of characters that define a search pattern. They are used to match, find, replace, and validate text strings across virtually every modern programming language, text editor, and development tool. This regex tester uses the JavaScript (ECMAScript) regex engine, which powers modern web browsers and Node.js. By testing your patterns against sample text instantly, you can refine your regex logic without the overhead of writing and running separate code. The tool displays all matches, their positions, and any capture groups extracted from the test string, helping you verify correctness before using patterns in production code.

How to Use This Regex Tester

Enter your regular expression pattern in the "Regular Expression Pattern" field without slashes. For example, to match email addresses, you might use^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. Next, select any flags you need from the checkboxes: global (g) to find all matches, ignore case (i) for case-insensitive matching, multiline (m) to treat line breaks as boundaries, dotAll (s) to match newlines with the dot operator, unicode (u) for Unicode pattern matching, and sticky (y) for anchored matches. Then paste or type your test string into the "Test String" textarea. The tool will instantly build a regex object, execute it against your test string, and display all matches with their indices, capture groups, and highlighted sections in the original string. If your pattern is invalid, an error message will appear explaining the syntax problem.

Common Regex Tokens and Syntax

Regular expressions use a concise syntax to describe patterns. Here are the most frequently used tokens:

Understanding Flags

Regex flags modify how the pattern matching behaves. The global flag (g)causes the regex engine to find all matches in the string instead of stopping after the first match. The ignore case flag (i) makes matching case-insensitive, so "A" and "a" are treated identically. The multiline flag (m) treats ^ and $ as line boundaries rather than string boundaries, useful when working with multi-line text. The dotAll flag (s) allows the dot (.) to match newline characters, which it normally does not. The unicode flag (u)enables Unicode pattern matching, crucial for handling emoji and international characters correctly. The sticky flag (y) makes the regex match only at the position indicated by its lastIndex property, anchoring subsequent matches.

Frequently Asked Questions

What regex engine does this tool use?

This tool uses the JavaScript (ECMAScript) regex engine, which is the standard for browsers and Node.js. For comprehensive documentation, see the MDN Regular Expressions guide. Keep in mind that other languages (Python, Java, Perl) have slightly different syntax and features.

What is a capture group and how do I use it?

A capture group is a portion of the regex pattern enclosed in parentheses(). It extracts and remembers the matched text. For example, in the pattern(\w+)@(\w+), there are two capture groups: one for the username and one for the domain. When the regex matches "john@example", Group 1 contains "john" and Group 2 contains "example". Capture groups are displayed in the results of this tool.

How can I match special characters like dots or parentheses?

Special regex characters (like . * + ? [ ] ( ) ^ $ |) have special meaning in patterns. To match them literally, escape them with a backslash\. For example, \.matches a literal period, \(matches a literal parenthesis, and \\matches a literal backslash.