UnitConv
Regex

Regex Tester

Test regular expressions with real-time match highlighting and capture group display

Regular Expression

//g

About this tool

The regex tester is a free tool that shows in real time how your pattern matches a piece of text. It highlights every match, counts them, and extracts capture groups and named groups at a glance. It is invaluable for building form validation, extracting data from logs, and writing replacement rules, and it includes a cheat sheet so you can look up the meaning of each metacharacter quickly.

How to use

  1. 1 Type your regular expression into the pattern field.
  2. 2 Paste the text you want to test into the test-string field.
  3. 3 Matching portions are highlighted, with the count and details shown.
  4. 4 Review the extracted capture groups and named groups.

How it works

A regular expression is a small language for describing patterns in text. Key metacharacters include: - "." matches any single character, "\d" a digit, "\w" a word character, and "\s" whitespace. - "*" means zero or more of the previous item, "+" one or more, "?" zero or one, and "{2,4}" two to four repetitions. - "^" anchors the start of a line, "$" the end, "[abc]" matches a, b, or c, and "(...)" forms a capture group. A simple email check might be "^\w+@\w+\.\w+$". Note that "*" and "+" are greedy by default and match as much as possible; add "?" (as in "*?") for the shortest match. Detailed behavior differs between flavors such as JavaScript, Python, and PHP, so keep your target environment in mind.

Frequently asked questions

What is the difference between greedy and lazy matching?

Greedy quantifiers (* and +) match as much as possible, while lazy ones (*? and +?) match as little as possible. The distinction matters when extracting HTML tags so you do not grab too much.

What is a capture group?

It is a part of the match enclosed in parentheses () that you can retrieve afterward, letting you pull out, say, the year, month, and day of a date separately.

What are regex flavors?

They are dialects of different implementations such as JavaScript, Python, and PCRE. Lookaround and named groups can be written differently, so match your runtime.

How do I search for a special character literally?

Escape characters that have meaning, like "." or "*", with a preceding backslash. For a literal period, write "\.".

Related tools and uses

To check the code value of a character, see the ASCII converter, and for string-processing fundamentals the number base converter helps. For mathematical patterns, the equation solver is also useful.