Regex Tester

Test regular expressions and highlight matches in real time.

Input data is processed in your browser
Data is never sent to a server

Tool

//

or drag & drop a file

What is a Regular Expression?

A regular expression (regex) is a notation for describing a set of strings using a single pattern. It enables concise expression of complex string searching, replacing, and validation operations. This tool highlights matches in real time as you type the pattern or test text, and lists each matched string along with its position (index) in the text.

When this comes in handy

  • You want to pull strings matching a specific pattern — like email addresses or URLs — out of a block of text: enter a pattern and every matching span in the text is highlighted, with the extracted results listed below.
  • You want to try out a validation rule (phone numbers, postal codes, etc.) before wiring it into your code: type sample input and immediately see whether it matches or not, exactly as your code would evaluate it.
  • You need to pick out only the lines that match a condition from a multi-line log or CSV: use the m flag to anchor patterns to the start/end of each line and evaluate lines individually.
  • You want to sanity-check a regex before using it in a replace operation: the highlighting makes it easy to spot matches that are wider than intended before that pattern goes anywhere near your code.

Usage examples

Example 1: Extracting email addresses

Pattern: [a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,} Flags: gi

Test text:

example@email.com, test.user@domain.jp
Contact us at Contact@Example.com

Because of the i flag, matching is case-insensitive, so all three addresses appear in the results:

#1 example@email.com       Index: 0
#2 test.user@domain.jp     Index: 19
#3 Contact@Example.com     Index: 53

Example 2: How the g flag changes the result

Pattern: \d+ Test text: id: 12, 34, 56

With g included in the flags, all three numbers — 12, 34, 56 — match. Remove g and only the first match, 12, appears in the results. Keep the g flag on whenever you want to search the whole text rather than just the first occurrence.

Example 3: Ignoring case with the i flag

Pattern: error Test text: ERROR: Connection failed / error: timeout

Without the i flag, only the lowercase error matches. Add i (as in gi) and the uppercase ERROR matches too. This is useful for searching logs where casing isn’t consistent.

Example 4: Anchoring to line starts with the m flag

Pattern: ^\d+ Flags: gm Test text:

100 apple
200 banana
300 cherry

^ normally matches only the very start of the whole text, but the m (multiline) flag makes it match the start of every line instead, so 100, 200, and 300 all match. Remove the m flag and only the 100 at the very start of the text matches.

How to Use

  1. Enter a regex pattern in the pattern field.
  2. Enter test text in the text area.
  3. Matches are highlighted in real time.
  4. Adjust flags (g, i, m) as needed.

FAQ

Which regex engine is used?

JavaScript's built-in regular expression engine. Some syntax may differ from other languages (such as Python's `re` module or PCRE), so double-check against the target language's spec before porting a pattern.

What's shown in the match results list?

The matched text itself, plus its starting position (index) in the test text. It doesn't currently break results down by capture group (e.g. `match[1]`); use your browser's developer console if you need per-group values.

What happens if I don't use the g flag?

Without the g (global) flag, only the first match found is shown in the results list and highlighted. Add the g flag if you want to see every occurrence in the text.

Can I drag and drop a text file?

Yes. Drop a .txt file (under 5MB) onto the "Test Text" field and its contents are loaded automatically.

What happens if I enter an invalid regex?

An "Invalid regular expression" error is shown along with details of the syntax error, such as an unsupported group construct or a missing closing bracket.

Are matches highlighted in real time?

Yes. The pattern is re-evaluated automatically as you type either the pattern or the test text, and matches are highlighted with a background color — no button click required.