niftytools.dev
advertisement

Regex Tester

Write and test regular expressions against any text. See all matches highlighted in real time with capture group details.

//gi
advertisement
advertisement

What is a Regular Expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. Regex allows you to describe complex text patterns in a compact, precise syntax that can match, extract, validate, or replace parts of a string. A pattern like\d{3}-\d{4} matches any string formatted like a phone number segment. Regular expressions are supported in virtually every programming language and are built into the string methods of JavaScript, Python, Java, and many others. Mastering regex eliminates entire categories of manual string manipulation.

Common Regex Patterns

  • Email address[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
  • URLhttps?:\/\/[^\s/$.?#].[^\s]*
  • IP address(\d{1,3}\.}{3}\d{1,3}
  • Date (YYYY-MM-DD)\d{4}-\d{2}-\d{2}
  • Hex colour#[0-9a-fA-F]{3,6}
  • Whitespace normalisation\s+ replaced with a single space

Regex Flags Reference

  • g (global) — Find all matches in the string rather than stopping at the first match.
  • i (case-insensitive) — Match uppercase and lowercase letters interchangeably.
  • m (multiline) — Make ^ and $ match the start and end of each line rather than just the whole string.
  • s (dotAll) — Make the . metacharacter match newline characters as well as other characters.

How to Test a Regular Expression

  1. Type your pattern into the regex field — no need to add the surrounding / / delimiters.
  2. Paste the text you want to search into the test-string box.
  3. Toggle flags (g, i, m, s) and watch every match highlight in real time, with capture groups listed below.

Because matching runs live in your browser, you can refine the pattern character by character and immediately see which parts of the text match — the fastest way to debug a tricky expression before dropping it into your code.

Frequently Asked Questions

What is the difference between .* and .*?

.* is greedy — it matches as many characters as possible. .*? is lazy (non-greedy) — it matches as few characters as possible. For example, applied to<b>text</b>, the pattern <.*> matches the entire string (greedy), while <.*?> matches only <b> (lazy).

What does ^ and $ mean in a regex?

^ is the start-of-string anchor — the pattern must match at the beginning of the string.$ is the end-of-string anchor — the pattern must match at the end. Together,^pattern$ ensures the entire string matches the pattern (no partial matches). With the multilinem flag, they match the start and end of each line.

Why does my regex work in JavaScript but not in Python?

Different languages implement slightly different regex flavours. JavaScript uses the ECMAScript regex engine. Python's re module uses a POSIX-influenced engine. Key differences include named capture groups ((?P<name>...) in Python vs (?<name>...)in JavaScript), lookbehind support, and Unicode handling. This tester uses JavaScript's regex engine.

How do I match a literal dot or bracket in regex?

Metacharacters like . * + ? ( ) [ ] { } ^ $ | have special meaning in regex. To match them literally, escape them with a backslash:\.  matches a literal dot,\[ matches a literal open bracket. Inside a character class [ ], most metacharacters lose their special meaning and do not need escaping.

How do I use capture groups?

Wrap part of a pattern in parentheses ( ) to capture whatever it matches into a numbered group. For example(\d{4})-(\d{2}) pulls the year and month out of a date separately. Use (?<name>...) for named groups. This tester lists every captured group beneath each match.

Is my regex or test text sent to a server?

No. The tester compiles and runs your pattern entirely in your browser with the native JavaScript regex engine. Neither the pattern nor the text you paste is uploaded or stored, so you can safely test against private log data or sample records.