正在加载,请稍候…

Regex tester

Test regular expressions with real-time match highlighting, capture groups, and named groups. Includes a cheat sheet and pattern explanation for quick reference.

How to Use

  1. Step 1: Enter a regular expression in the top input.
  2. Step 2: Enter test text in the middle panel.
  3. Step 3: Matches are highlighted and listed below with group details.

Frequently Asked Questions

What regex flags are supported?

Supported flags: g (global), i (case-insensitive), m (multiline), s (dotAll), u (unicode), v (unicode sets).

How do I use capture groups?

Use parentheses () for numbered groups, (?<name>...) for named groups. Both are shown in the match results.

How do I make a regex match the entire string, not just part of it?

Use anchors: ^ matches the start of the string, and $ matches the end. For example, /^[0-9]{4}$/ matches exactly 4 digits. In multiline mode (m flag), ^ and $ match the start and end of each line rather than the whole string. Without anchors, the pattern can match anywhere inside the string.

How do I optimize a regex that causes catastrophic backtracking (ReDoS)?

Catastrophic backtracking is the root of ReDoS (Regular Expression Denial of Service) attacks and is common with nested quantifiers like (a+)+. Optimization strategies: avoid nested quantifiers; use atomic groups or possessive quantifiers to prevent backtracking; move fixed parts outside of groups; use anchors (^ $) to limit the match scope; test boundary cases (strings of repeated characters). A regex tool that shows step count can help — over 1 million steps indicates ReDoS risk.