Regex Tester

By Asira Tools Team · Last updated 20 November 2026

Test JavaScript regular expressions against your text and see every match with its exact position — with instant feedback when a pattern is invalid.

Advertisement

Regex Tester

3 matches found
Match count3
Matches"42" at 6, "3" at 13, "199" at 29

Patterns use JavaScript regular expression syntax. Flags: g = all matches, i = ignore case, m = multiline. Invalid patterns show an error instead of crashing.

Quick syntax:

\d = digit  |  \w = word character  |  \s = whitespace  |  . = any character  |  * = zero or more  |  + = one or more  |  ? = zero or one  |  {n,m} = between n and m  |  [abc] = character class  |  ( ) = group  |  | = or  |  ^ = start  |  $ = end

What Is a Regular Expression?

A regular expression, or regex, is a pattern that describes a set of strings. Instead of searching for one exact piece of text, you describe the shape of the text you want: "three digits, then a hyphen, then four digits" finds phone numbers; "letters, then an at sign, then a domain" finds email addresses. Regexes are built into almost every programming language, text editor, and search tool, and they are the standard way to validate input, extract data from logs, and find and replace text in bulk.

A regex is written as a compact string of characters, some literal and some special. The pattern \d+ means "one or more digits", because \d stands for any digit and + means "one or more of the previous thing". The pattern [a-z]+ means "one or more lowercase letters". Combining these building blocks lets you describe surprisingly precise patterns: \d{4}-\d{2}-\d{2} matches dates in the form 2026-11-20, and nothing else shaped differently. This tool uses JavaScript regular expression syntax, which is shared by most modern languages with only small differences.

How to Use This Tester

Type a pattern into the pattern box, add flags such as g for global matching, and type or paste the text you want to test into the test text box. The results update as you type, showing how many matches were found and listing each match with its starting position. The default example finds the numbers in an order summary: the pattern \d+ with the g flag finds "42" at position 6, "3" at position 13, and "199" at position 29.

If you are learning, start with the preset patterns. Choose one from the dropdown to load a ready-made pattern for numbers, email addresses, dates, URLs, or hex colors, then change the test text and watch what matches and what does not. If your pattern has a syntax error, such as an unclosed bracket, the tool shows the error message instead of crashing, so you can fix the pattern and keep testing.

The Building Blocks of a Pattern

Every regex is assembled from a small set of pieces. Character classes match one character from a set: \d matches any digit, \w matches any word character (letters, digits, and underscore), \s matches any whitespace, and a dot matches any character except a newline. Square brackets define your own set: [aeiou] matches any vowel, [0-9] matches any digit, and [^0-9] matches any character that is not a digit, because the caret inside brackets means "not".

Quantifiers say how many times the previous piece may repeat: * means zero or more, + means one or more, ? means zero or one, {3} means exactly three, and {2,4} means between two and four. Anchors pin the match to a position: ^ matches the start of the text (or the start of a line with the m flag) and $ matches the end. Parentheses group pieces together and capture what they match, and the pipe symbol means "or": cat|dog matches either word. A backslash escapes a special character so it is treated literally: \. matches a real dot, and \\ matches a real backslash.

Flags: g, i, m, and More

Flags change how a pattern behaves. The g flag, for global, finds every match in the text instead of stopping at the first one. Without it, this tester returns only the first match, which is useful when you only care whether a pattern matches at all. The i flag makes matching case-insensitive, so the pattern hello with the i flag matches "HELLO", "Hello", and "hello". The m flag, for multiline, makes ^ and $ match the start and end of each line instead of the whole text, which matters when your test text has several lines.

JavaScript also supports the s flag, which lets a dot match newline characters, the u flag for full Unicode support, and the y flag for sticky matching from a specific position. You can combine flags freely: gi means global and case-insensitive. A common beginner mistake is forgetting the g flag and wondering why only the first match appears, so check the flags first when your results look short.

Greedy Versus Lazy Matching

By default, quantifiers are greedy: they match as much text as they possibly can. The pattern <.+> applied to "<b>bold</b>" matches the entire string, because .+ grabs everything up to the last closing angle bracket, not the first. Adding a question mark makes a quantifier lazy, so it matches as little as possible: <.+?> matches just "<b>" first. This greedy-versus-lazy distinction is one of the most common sources of surprising regex results, and it is worth testing explicitly whenever your pattern uses . with a quantifier.

Another subtlety is that a regex engine scans from left to right and reports the leftmost match first. In the text "aaa", the pattern a+ matches the whole "aaa" as one match, not three separate matches, because the + quantifier is greedy and consumes all three letters at once. With the g flag, the engine then continues after the end of that match, so there is nothing left to find. Understanding this leftmost-first, greedy-by-default behavior explains most results that look wrong at first glance.

Worked Example: Finding Numbers in Text

Take the test text "Order 42 has 3 items, total $199" and the pattern \d+ with the g flag. The engine scans from the left: the letters in "Order" do not match \d, so it moves on. At position 6 it finds "4", a digit, and the + quantifier keeps consuming digits, so it matches "42" and stops at the space. It continues scanning, finds "3" at position 13, and then finds "199" at position 29, after the dollar sign. The result is three matches: "42" at 6, "3" at 13, and "199" at 29.

Remove the g flag and the same pattern returns only the first match, "42" at 6, because the engine stops after one success. Change the pattern to \d and it matches each digit separately, giving six matches: "4" at 6, "2" at 7, "3" at 13, "1" at 29, "9" at 30, and "9" at 31. Change it to \$\d+ and it matches only "$199" at position 28, because the dollar sign anchors the match to the price. Each small change to the pattern changes the results in a predictable way, and testing those changes here is the fastest way to build intuition.

Common Mistakes to Avoid

Forgetting to escape special characters. A dot matches any character, so the pattern example.com also matches "exampleXcom". If you mean a literal dot, write \. The same applies to +, *, ?, (, ), [, ], {, }, |, ^, $, and backslash itself.

Using regex to parse HTML or deeply nested data. Regular expressions cannot count nesting, so they cannot reliably match nested tags or balanced brackets. Use a real parser for HTML, JSON, and XML; use regex for flat, line-shaped text such as logs, IDs, and simple formats.

Writing patterns that backtrack catastrophically. A pattern such as (a+)+$ applied to a long string of a's followed by a different character can take an exponentially long time to fail, because the engine tries every possible way to split the input. This is called catastrophic backtracking, and it can freeze a page or a server. Keep nested quantifiers simple, and test patterns against long inputs before deploying them.

Validating emails with an overcomplicated pattern. The official email standard allows addresses that no reasonable regex can fully describe. For form validation, a simple pattern that checks for something, an at sign, and a domain is enough, and the real check is sending a confirmation email. The preset email pattern in this tool follows that pragmatic approach.

Trusting a regex you have only tested on matching input. A pattern that finds what you want is only half the job. Test it against text that should not match, including empty strings, very long strings, and edge cases, before you rely on it. This tester makes that easy: paste in your awkward cases and confirm the match count is what you expect.

Advertisement

Frequently Asked Questions

What does the g flag do in a regex?

The g flag means global: the pattern finds every match in the text instead of stopping at the first one. Without g, a search returns only the first match. Combine it with i for case-insensitive global matching.

Why does my regex only match part of the text?

Quantifiers are greedy by default, so a pattern like .+ matches as much as possible, which can swallow more than you intended. Add a ? after the quantifier (for example .+?) to make it lazy so it matches as little as possible.

How do I match a literal dot or other special character?

Escape it with a backslash: \. matches a real dot, \+ matches a real plus sign, and \\ matches a real backslash. Unescaped, those characters have special meanings in a pattern.

What is the difference between \d, \w, and \s?

\d matches any digit (0-9), \w matches any word character (letters, digits, and underscore), and \s matches any whitespace character (space, tab, newline). Their uppercase versions \D, \W, and \S match the opposite sets.

Can I use this tester for Python or other languages?

Mostly yes. This tester uses JavaScript regex syntax, which shares its core features with Python, Java, PHP, and most other languages. Small differences exist, such as lookbehind support and named group syntax, so always re-test a pattern in your target language before shipping it.