checkersRegex Tester

Regex Tester

Test and validate regular expressions with live matching

Common Patterns (Click to use)

Quick Reference

Character Classes:

  • • \d - Digit (0-9)
  • • \w - Word character
  • • \s - Whitespace
  • • . - Any character

Quantifiers:

  • • * - 0 or more
  • • + - 1 or more
  • • ? - 0 or 1
  • • {n,m} - Between n and m

Anchors:

  • • ^ - Start of string
  • • $ - End of string
  • • \b - Word boundary

Groups:

  • • (x) - Capturing group
  • • (?:x) - Non-capturing
  • • [abc] - Character set
  • • [^abc] - Negated set

Free Regex Tester | Test Regular Expressions with Live Matching, Flags and Common Patterns

Regular expressions are one of the most powerful tools in a developer's toolkit and one of the most frustrating to write correctly without immediate feedback. A single misplaced backslash, a forgotten escape character, or an incorrect quantifier produces a pattern that matches everything, matches nothing, or matches the wrong things entirely.

Thetoolity's free regex tester provides a live testing environment for regular expressions. Enter your pattern, select flags (global, case-insensitive, multiline, dot-all), paste your test string, and see matches highlighted in real time. Six ready-to-use common patterns cover the most frequent use cases, and a built-in quick reference covers character classes, quantifiers, anchors, and groups so you do not need to switch to documentation while building your pattern.

No account. No installation. Runs entirely in your browser using JavaScript's native regex engine.

How to Use the Regex Tester

Step 1: Enter your regular expression pattern

Type or paste your regex pattern into the Pattern field. Do not include the opening and closing forward slashes that you would write in JavaScript source code: enter only the pattern itself. For example, enter [a-zA-Z]+ rather than /[a-zA-Z]+/.

Step 2: Select flags

Four flags are available as toggle buttons. Use any combination:

  • Global (g): finds all matches in the test string rather than stopping at the first match. Without the global flag, most regex operations return only the first match.

  • Case Insensitive (i): makes the pattern match regardless of letter case. The pattern [a-z]+ with the i flag matches "hello," "HELLO," and "Hello" equally.

  • Multiline (m): changes the behavior of the ^ and $ anchors. Without multiline, ^ matches the start of the entire string and $ matches the end of the entire string. With multiline, ^ matches the start of each line and $ matches the end of each line.

  • Dot All (s): makes the dot (.) match any character including newline characters. Without the s flag, a dot matches any character except newlines.

Step 3: Enter a test string

Paste or type the text you want to test your pattern against. The test string can be any length and can contain multiple lines. Use realistic examples of the data you want to match: email addresses, URLs, log file lines, JSON snippets, or any other content your pattern will be applied to in production. Results appear as soon as both a pattern and a test string have been entered, and they update as you keep typing or toggle flags.

Step 4: Use common patterns as starting points

Six built-in common patterns are available as one-click starters:

  • Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

  • URL: https?://[^\s]+

  • Phone (US): \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}

  • IP Address: \b(?:\d{1,3}\.){3}\d{1,3}\b

  • Hex Color: #[0-9a-fA-F]{6}

  • Date (YYYY-MM-DD): \d{4}-\d{2}-\d{2}

Click any pattern to load it into the pattern field. You can then modify it for your specific requirements.

Step 5: Review matches

The tester shows a match count, your test string with every match highlighted, and a numbered list of each matched text under Match Details, so you can quickly confirm whether the pattern is capturing what you intend. If the pattern is not valid, the tool shows an "Invalid Pattern" message with the error from the regex engine. The tester lists the full text of each match; it does not display the contents of individual capture groups.

Step 6: Iterate and refine

Modify the pattern and watch the matches update. This iterative feedback loop is the most effective way to build and refine regular expressions. Test both strings that should match and strings that should not match to confirm your pattern is correctly bounded.

Regular Expression Syntax Reference

The quick reference in Thetoolity's regex tester covers the four fundamental building blocks of regular expressions: character classes, quantifiers, anchors, and groups. Understanding each one gives you the ability to write patterns for virtually any text-matching requirement. This section goes a little further than the quick reference.

Character Classes

Character classes specify what kind of character can match at a given position in the pattern.

  • \d: matches any digit (0 through 9). Equivalent to [0-9].

  • \D: matches any character that is not a digit. Equivalent to [^0-9].

  • \w: matches any word character: letters (a-z, A-Z), digits (0-9), and the underscore. Equivalent to [a-zA-Z0-9_].

  • \W: matches any non-word character. Everything not matched by \w.

  • \s: matches any whitespace character: space, tab, newline, carriage return, form feed, vertical tab, and other Unicode space characters.

  • \S: matches any non-whitespace character.

  • . (dot): matches any single character except a newline. With the s (dot-all) flag, it matches newlines too.

  • [abc]: a character class in square brackets matches any one of the listed characters. [aeiou] matches any vowel.

  • [^abc]: a negated set matches any character except those listed.

  • [a-z]: a range within a character class. [a-z] matches any lowercase letter, [0-9] matches any digit, and [a-zA-Z] matches any letter.

Quantifiers

Quantifiers specify how many times the preceding element must match.

  • *: zero or more times. a* matches an empty string, "a", "aa", "aaa", and so on.

  • +: one or more times. a+ matches "a", "aa", "aaa" but not an empty string.

  • ?: zero or one time. colou?r matches both "colour" and "color" (the u is optional).

  • {n}: exactly n times. \d{4} matches exactly four digits.

  • {n,}: at least n times. \d{2,} matches two or more digits.

  • {n,m}: between n and m times (inclusive). \d{2,4} matches two, three, or four digits.

Greedy vs lazy quantifiers

By default, quantifiers are greedy: they match as many characters as possible while still allowing the overall pattern to match. Adding a ? after a quantifier makes it lazy (also called non-greedy), matching as few characters as possible.

  • Greedy: .+ applied to "abc def" matches "abc def" (the entire string). Lazy: .+? applied to "abc def" matches "a" (the shortest possible match).

  • Greedy: <.+> applied to "<b>text</b>" matches the whole string (everything between the first < and the last >). Lazy: <.+?> applied to the same string matches "<b>" first (the shortest possible match within angle brackets).

Understanding greedy vs lazy quantifiers is one of the most important concepts for writing regex that matches exactly what you intend.

Anchors

Anchors do not match characters: they match positions in the string.

  • ^: without the multiline flag, matches the start of the entire string. With the multiline flag, matches the start of each line.

  • $: without the multiline flag, matches the end of the entire string. With the multiline flag, matches the end of each line.

  • \b: word boundary. Matches the position between a word character and a non-word character, or the start or end of the string if the first or last character is a word character. \bcat\b matches "cat" in "the cat sat" but not the "cat" within "concatenate".

  • \B: non-word boundary. Matches any position that \b does not match.

Groups

Groups allow you to apply quantifiers to multiple characters, capture matched substrings, or create alternatives.

  • (x): capturing group. Matches x and captures the match for later reference. In JavaScript, the captured groups are accessible in the match result array.

  • (?:x): non-capturing group. Matches x but does not capture it. Use this when you want to group characters for quantifier application without needing the captured value.

  • x|y: alternation. Matches either x or y. cat|dog matches "cat" or "dog".

  • (?=x): positive lookahead. Matches a position followed by x, but does not include x in the match. \d+(?= dollars) matches "100" in "100 dollars" but not in "100 euros".

  • (?!x): negative lookahead. Matches a position not followed by x.

  • (?<=x): positive lookbehind. Matches a position preceded by x.

  • (?<!x): negative lookbehind. Matches a position not preceded by x.

The Six Common Patterns Explained

Each of the six built-in common patterns in Thetoolity's tester represents a frequently needed matching task. Understanding how each pattern is constructed helps you adapt them for your specific requirements.

Email pattern

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

  • [a-zA-Z0-9._%+-]+: one or more characters that can be letters, digits, dots, underscores, percent signs, plus signs, or hyphens. This covers the local part before the @.

  • @: the literal @ symbol.

  • [a-zA-Z0-9.-]+: one or more characters for the domain portion before the TLD: letters, digits, dots, and hyphens.

  • \.: an escaped dot (the backslash makes it a literal dot rather than the "any character" wildcard).

  • [a-zA-Z]{2,}: two or more letters for the top-level domain (.com, .org, .io, .photography, etc.).

Limitation: this is a format-checking pattern, not a comprehensive email validation regex. It accepts many technically invalid addresses and rejects some technically valid ones (such as those with quoted local parts). For production email validation, combine a pattern check like this with server-side verification.

URL pattern

https?://[^\s]+

  • https?: matches "http" or "https". The s? makes the s optional.

  • ://: the literal colon and double slash.

  • [^\s]+: one or more characters that are not whitespace. This matches everything in the URL up to the first space or line break.

Limitation: this is a loose URL matcher. It matches the protocol and everything after it until whitespace. It does not validate domain format, path structure, or query string format. For stricter URL validation, use more complex patterns or the URL constructor approach.

Phone (US) pattern

\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}

  • \(?: an optional literal opening parenthesis. The backslash escapes the parenthesis (otherwise it would start a group).

  • \d{3}: exactly three digits (the area code).

  • \)?: an optional literal closing parenthesis.

  • [-.\s]?: an optional separator: hyphen, dot, or whitespace character.

  • \d{3}: exactly three digits (the exchange code), followed by another optional separator.

  • \d{4}: exactly four digits (the subscriber number).

This pattern matches (555) 123-4567, 555-123-4567, 555.123.4567, and 5551234567 (no separator). Limitation: it does not validate that the area code or exchange is real or currently assigned, and international phone numbers require different patterns.

IP Address pattern

\b(?:\d{1,3}\.){3}\d{1,3}\b

  • \b: word boundary at the start.

  • (?:\d{1,3}\.){3}: a non-capturing group matching 1 to 3 digits followed by a literal dot, repeated exactly 3 times. This matches the first three octets with their dots.

  • \d{1,3}: 1 to 3 digits for the fourth octet.

  • \b: word boundary at the end.

Limitation: this pattern matches the format of an IP address (groups of 1 to 3 digits separated by dots) but does not validate that each octet is within the 0 to 255 range. The string 999.999.999.999 passes this pattern. For strict IP validation, use Thetoolity's dedicated IP address validator.

Hex Color pattern

#[0-9a-fA-F]{6}

  • #: the literal hash character that begins CSS hex colors.

  • [0-9a-fA-F]: a character class matching any hexadecimal digit (0-9, a-f, upper or lowercase).

  • {6}: exactly 6 hexadecimal characters following the #.

This matches standard 6-digit hex colors (#ffffff, #FF0000, #1a2b3c). It does not match the 3-digit shorthand (#fff) or the 8-digit form with alpha (#ffffff80). To cover those too, you can use alternation, for example #(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3}).

Date (YYYY-MM-DD) pattern

\d{4}-\d{2}-\d{2}

  • \d{4}: exactly four digits for the year.

  • -: a literal hyphen.

  • \d{2}: exactly two digits for the month, then another hyphen and two digits for the day.

This matches the ISO 8601 date format (2024-03-15, 2000-01-01). Limitation: this pattern matches the format but does not validate that the values represent a real date. 2024-99-99 passes this pattern. Calendar validation requires additional logic beyond the regex match.

Regex Flags in Detail

The four flags available in Thetoolity's regex tester control how the matching engine interprets the pattern and test string.

Global flag (g): finding all matches

Without the global flag, JavaScript's regex engine finds the first match and stops. The global flag makes it continue scanning through the entire string after each match, returning all matches. This is essential when you need to find every occurrence of a pattern in a text: every email address in a document, every URL in a web page, every phone number in a data export.

  • Without g: "hello world hello".match(/hello/) finds only the first "hello".

  • With g: "hello world hello".match(/hello/g) returns both occurrences.

Case Insensitive flag (i): case-agnostic matching

Makes the pattern match regardless of the case of letters. Essential when the case of the input is unpredictable or irrelevant.

  • Without i: /hello/.test("Hello") returns false. With i: /hello/i.test("Hello") returns true.

  • When to use: user input validation where you want to accept both "john@example.com" and "JOHN@EXAMPLE.COM", case-agnostic search, or HTML parsing where tag names may be any case.

Multiline flag (m): per-line anchoring

Changes ^ and $ from matching the start and end of the entire string to matching the start and end of each line.

Test string: line one\nline two\nline three (three lines).

  • Without m: ^line matches only at the very start, so only "line one" is found.

  • With m (and g to find all matches): ^line matches at the start of each line, so all three lines are found.

  • When to use: processing multi-line text files or log entries where you need to match patterns at the beginning or end of each line rather than the entire string.

Dot All flag (s): matching newlines with a dot

By default, the dot (.) matches any character except a newline. The s flag removes this exception.

  • Without s: .+ applied to two lines ("line one" then "line two") matches "line one" only.

  • With s: .+ matches both lines (the dot crosses the newline boundary).

  • When to use: matching content that may span multiple lines, such as multi-line HTML elements, JSON blocks, or log entries that wrap across lines.

JavaScript has additional flags, such as u (Unicode) and y (sticky), that are not offered as buttons in this tool but can be used in your own code.

Common Regex Mistakes and How to Fix Them

Forgetting to escape special characters

Many characters have special meanings in regex: . * + ? ^ $ { } [ ] | ( ) \. When you want to match these characters literally, they must be escaped with a backslash.

  • To match a literal dot (as in a file extension), use \. rather than . (the unescaped dot matches any character).

  • To match a literal parenthesis, use \( and \).

  • To match a literal backslash, use \\ (two backslashes).

  • Common mistake: writing a domain pattern as example.com (the dot matches any character, so it also matches "exampleXcom") instead of example\.com.

Over-greedy matching

A greedy quantifier like .+ in a pattern like <.+> applied to "click <a>here</a> and <b>there</b>" matches everything from the first < to the last > rather than just the first tag. Use lazy quantifiers (<.+?>) to match the shortest possible string.

Missing anchors causing partial matches

Without anchors, a pattern matches anywhere within the string. \d{4} matches "1234" within "abc1234xyz" even though you may only want to match strings that are entirely four digits. Use ^ and $ anchors to constrain the match to the full string: ^\d{4}$ matches only strings that are exactly four digits and nothing else.

Incorrect quantifier on character classes

[abc]+ means "one or more of a, b, or c". A common mistake is writing [abc+], which means "any single character that is a, b, c, or +" (the + inside square brackets is a literal character, not a quantifier). Quantifiers must appear outside the closing square bracket.

Not accounting for Unicode

In JavaScript, the shortcuts \w and \d only match ASCII characters, so \w+ will not match a word like "café" in full. For patterns that need to match international letters or digits, use the u flag together with Unicode property escapes such as \p{L} (any letter) in your own code.

Catastrophic backtracking

Certain regex patterns can cause exponential backtracking when applied to certain inputs, causing the regex engine to hang or time out. This is called catastrophic backtracking and occurs with nested quantifiers on overlapping character classes, such as (a+)+b applied to a long string of a's not followed by b.

For web applications processing user-supplied input with regex, this is a real security concern (ReDoS: regular expression denial of service). Avoid patterns with nested quantifiers on the same character class. Because a live tester re-runs your pattern as you type, a pattern like this combined with a long test string can also freeze your browser tab, so test risky patterns with short strings first.

Regex in JavaScript: Practical Usage

Thetoolity's regex tester uses JavaScript's native regex engine (the same engine used in Node.js and all major browsers), making it directly applicable to JavaScript and TypeScript development.

Creating a regex in JavaScript

  • Literal syntax (compiled when the script loads): const pattern = /[a-zA-Z]+/gi;

  • Constructor syntax (compiled at runtime, useful for dynamic patterns): const pattern = new RegExp('[a-zA-Z]+', 'gi');. Remember that backslashes must be doubled inside a normal string, for example new RegExp('\\d+').

Common JavaScript regex methods

  • String.prototype.match(regex): returns an array of all matches with the g flag, or the first match with its capture group details without g.

  • String.prototype.matchAll(regex): returns an iterator of all matches with capture groups (requires the g flag).

  • String.prototype.replace(regex, replacement): replaces matches with a replacement string or function.

  • String.prototype.replaceAll(regex, replacement): like replace but replaces all matches (requires the g flag when given a regex).

  • String.prototype.split(regex): splits a string at each match.

  • String.prototype.search(regex): returns the index of the first match, or -1.

  • RegExp.prototype.test(string): returns true if the pattern matches anywhere in the string.

  • RegExp.prototype.exec(string): returns details about the next match (used in loops with the g flag).

Named capture groups (ES2018)

(?<name>x) creates a named capture group. The matched value is accessible by name in the result. For example, matching "2024-03-15" against (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) gives you match.groups.year ("2024"), match.groups.month ("03"), and match.groups.day ("15"). Named groups make regex code significantly more readable than accessing capture groups by numeric index.

Frequently Asked Questions

What is a regex tester?+
A regex tester is a tool that lets you write a regular expression pattern and immediately see which parts of a test string it matches. Thetoolity's free regex tester provides live match highlighting, four flag options (global, case-insensitive, multiline, dot-all), six common ready-to-use patterns, and a quick reference for character classes, quantifiers, anchors, and groups.
What does the global (g) flag do in regex?+
The global flag makes the regex engine find all matches in the string rather than stopping at the first match. Without the g flag, matching returns only the first match. With g, it returns all occurrences. Essential when you need to find every email address, URL, or phone number in a body of text.
What does the multiline (m) flag do in regex?+
The multiline flag changes the behavior of ^ and $ anchors. Without multiline, ^ matches only the start of the entire string and $ matches only the end. With multiline, ^ matches the start of each line and $ matches the end of each line. Use it when processing multi-line text where you want per-line anchor behavior.
What is the difference between greedy and lazy quantifiers?+
Greedy quantifiers (*, +, ?) match as many characters as possible while still allowing the overall pattern to match. Lazy quantifiers (*?, +?, ??) match as few characters as possible. Example: applied to "<a>text</a>", the greedy .+ between angle brackets matches the entire string, while the lazy .+? matches only "<a>".
What does \b mean in regex?+
\b is a word boundary anchor. It matches the position between a word character (\w: letters, digits, underscore) and a non-word character, or at the start or end of the string. \bcat\b matches "cat" as a whole word but not the "cat" within "concatenate". It is essential for matching whole words rather than substrings.
How do I match a literal dot in regex?+
A dot (.) in regex matches any character. To match a literal dot character, escape it with a backslash: \. Use \. when matching file extensions, IP addresses, domain names, or decimal numbers where you want the actual period character rather than any character.
What is a non-capturing group in regex?+
A non-capturing group (?:x) groups characters for quantifier application or alternation without creating a captured result. Regular capturing groups (x) store the matched substring for later reference. Use (?:) when you need grouping but do not need to access the captured value, which keeps capture group numbering cleaner.
What is catastrophic backtracking in regex?+
Catastrophic backtracking occurs when a regex pattern with nested quantifiers on overlapping character classes is applied to a string that causes exponential search paths in the matching engine. Patterns like (a+)+b can cause a regex engine to hang on certain inputs. This is a real security concern (ReDoS) in web applications that apply regex to user-supplied input.

Why Thetoolity?

Thetoolity brings together a growing collection of free, fast, and clean online tools for developers, data analysts, and anyone who works with text processing. Our regex tester provides live match highlighting, four configurable flags, six common patterns as one-click starters, a built-in quick reference covering the fundamental regex syntax, and uses the same JavaScript regex engine your browser and Node.js applications use.

No accounts. No subscriptions. No cluttered interfaces. No data stored. Just a clean, instant regex testing environment in your browser.

Explore the full collection at Thetoolity.com and find generators, converters, calculators, checkers, and testers, all free and all instant.