Regex Tester

Test and debug regular expressions online. Highlight matches, test flags, and view capture groups.

//g

How to use Regex Tester

1

Enter Your Regular Expression

Click the 'Pattern' input field at the top of the editor. Type or paste your regex pattern (e.g., ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$). The pattern box accepts all standard regex syntax including anchors, character classes, and quantifiers.

2

Input Text to Test Against

Click the 'Test String' textarea below the pattern field. Paste or type the text you want to match against your regex. You can test multiple lines by pressing Enter. The tool will immediately process and display results in real-time.

3

Select Regex Flags

Check the flag checkboxes on the right side: 'g' (global - find all matches), 'i' (case-insensitive), 'm' (multiline), 's' (dotall), 'u' (unicode). Selected flags will modify how your pattern matches. The interface shows which flags are currently active in green.

4

Review Highlighted Matches

View the test string area where all matches are highlighted in yellow or blue. Each match is numbered sequentially. Hover over highlighted text to see the exact character position and matched content in the tooltip.

5

Examine Capture Groups

Scroll to the 'Capture Groups' panel below the text area. This table shows all matched groups with their content, position, and length. Each row represents one captured group (Group 0 is the full match, Group 1+ are parenthesized subexpressions).

6

Check Match Count and Details

View the 'Results' summary box showing total matches found, execution time, and any regex errors. If your pattern has syntax errors, the error message appears in red text explaining the issue and line number.

Related Tools

Regex tester online, test regular expressions with real-time highlighting

Regex tester online, test regular expressions with real-time highlighting

Need to test a regular expression before using it in code? Use ToolHQ's free regex tester to match patterns against sample text with live highlighting right in your browser.

ToolHQ's regex tester is a free browser-based tool that tests regular expressions against sample text in real time, highlights all matches, and shows captured groups, with your test data never leaving your browser.

Debugging a regex without an interactive tester means cycles of writing code, running it, reading output, and adjusting -- all while switching contexts. A live regex tester cuts that loop to seconds.

Key Takeaways

  • Real-time match highlighting updates instantly as you type your pattern or test text
  • Supports standard regex flags: g (global), i (case-insensitive), m (multiline), s (dotall)
  • Shows all matches and their captured groups in a structured list
  • Your test data never leaves your browser -- all matching happens in JavaScript locally
  • Free with no login and no rate limits

What is a regular expression and how does regex testing work?

A regular expression (regex or regexp) is a pattern used to match, search, extract, or replace strings of text. Regex patterns can describe anything from a simple word to complex rules like "a US phone number with or without country code and any delimiter."

According to MDN's Regular Expressions guide, JavaScript's regular expression engine supports:

  • Character classes: \d (digit), \w (word character), \s (whitespace)
  • Quantifiers: * (zero or more), + (one or more), {n,m} (between n and m times)
  • Anchors: ^ (start of string), $ (end of string), \b (word boundary)
  • Groups: () for capture groups, (?:) for non-capturing groups, (?=) for lookaheads
  • Flags: g for global (find all matches), i for case-insensitive, m for multiline, s for dotall

The Wikipedia article on regular expressions traces regex theory to mathematician Stephen Kleene's work in the 1950s. Regular expressions were first implemented in Unix tools like grep and sed in the 1970s, and are now built into virtually every programming language and many text editors.

ToolHQ's regex tester runs JavaScript's native regular expression engine in your browser. What matches in the tester will match in your JavaScript, Node.js, or TypeScript code.


When you need a regex tester

Writing regex patterns without instant feedback is like writing code without running it. The tester makes the iteration loop immediate.

Mini-story: Jasmine is a 27-year-old backend developer building a form validation system. She needed a regex to validate UK postcodes, which have a complex format (like "SW1A 1AA" or "M1 1AE"). She opened the regex tester, entered several valid and invalid UK postcode examples as test text, and iteratively refined her pattern: ^[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][A-Z]{2}$. With each adjustment, the tester immediately showed which test strings matched and which didn't. She had a working pattern in about eight minutes, including the case-insensitive flag. The alternative was running test code after each attempt -- easily four times slower.

Common situations where a regex tester is the right tool:

  • Validating regex patterns for form input validation (email, phone, postal code)
  • Extracting structured data from unstructured text (log files, API responses)
  • Writing search-and-replace patterns for text editors that support regex
  • Debugging why a regex isn't matching expected strings
  • Learning regex syntax by experimenting with patterns and immediate feedback

Test your regex at ToolHQ


How to use the regex tester

  1. Open ToolHQ's regex tester in your browser.
  2. Enter your regular expression in the pattern field (without the surrounding slashes -- just the pattern itself).
  3. Select your flags. Check g for all matches, i for case insensitive, m for multiline, s for dotall.
  4. Enter your test text in the test string area. This can be any text you want to match against.
  5. Watch matches highlight. Every match is highlighted immediately as you type. The match list below shows all captures.

Common regex patterns you can use right now

These six patterns cover the most frequent real-world matching tasks. Each is shown with the pattern string and a breakdown of how the key parts work.

Email address (basic validation) Pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} How it works: [a-zA-Z0-9._%+-]+ matches the local part (letters, digits, dots, underscores, percent, plus, hyphen, one or more times). @ matches the literal at sign. [a-zA-Z0-9.-]+ matches the domain name. \. matches a literal dot. [a-zA-Z]{2,} matches the top-level domain (two or more letters). Sufficient for most form validation; does not cover every RFC-valid edge case.

US phone number Pattern: \(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4}) How it works: \(? matches an optional opening parenthesis. (\d{3}) captures exactly three digits (area code) as group 1. \)? matches an optional closing parenthesis. [-.\s]? matches an optional separator (dash, dot, or space). The same pattern repeats for the exchange and subscriber number. Matches (555) 867-5309, 555.867.5309, 5558675309, and other common US formats.

URL match Pattern: https?://[^\s/$.?#].[^\s]* How it works: https? matches "http" or "https" (the ? makes the "s" optional). :// matches literally. [^\s/$.?#] matches any character that is not whitespace or a URL-ending character. [^\s]* matches the rest of the URL until whitespace. Captures full URLs including paths and query strings.

Date in YYYY-MM-DD format Pattern: \b\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\b How it works: \d{4} matches exactly four digits (year). (0[1-9]|1[0-2]) matches months 01 through 12 only (not 00 or 13). (0[1-9]|[12]\d|3[01]) matches days 01 through 31. \b word boundaries prevent matching dates embedded in longer strings. Does not validate calendar correctness (February 31 would match).

US ZIP code Pattern: \b\d{5}(-\d{4})?\b How it works: \d{5} matches exactly five digits. (-\d{4})? optionally matches a hyphen followed by four digits (the ZIP+4 extension). \b word boundaries prevent partial matches inside longer numbers. Matches 90210 and 90210-1234.

Hex color code Pattern: #([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\b How it works: # matches the literal hash character. [A-Fa-f0-9]{6} matches a 6-digit hex color (like #1a2b3c). | is alternation (or). [A-Fa-f0-9]{3} matches a 3-digit shorthand hex color (like #abc). The \b prevents matching #1a2b3c4 as #1a2b3c. Matches both #fff and #ffffff.

Mini-story: Owen, a 44-year-old data analyst, needed to extract all URLs from 500KB of raw HTML saved from a web scrape. He pasted a small sample into the regex tester, built a URL extraction pattern, and confirmed it matched only actual URLs -- not partial matches or JavaScript source references. Once the pattern worked correctly in the tester, he integrated it into his Python script using the re module. The tester prevented him from deploying a pattern that would have matched several false positives.

For URL encoding and decoding operations on matched URLs, use ToolHQ's URL encoder/decoder. For formatting JSON outputs from extraction, use the JSON formatter. Browse all developer tools in the ToolHQ developer category.


Frequently asked questions

Is my test data sent to a server?

No. ToolHQ's regex tester runs the pattern matching entirely in your browser using JavaScript's built-in RegExp engine. Your test data never leaves your browser.

Does this support regex flavors other than JavaScript?

The tester uses JavaScript's regex engine. JavaScript regex is similar to PCRE (PHP, Python, Java) but has some differences -- notably, JavaScript lacks lookbehind in older engines and some Unicode property escapes. Patterns that work in JavaScript's regex engine will work in the tester.

How do I use capture groups?

Wrap the part you want to capture in parentheses: (\d+). In the match list, each captured group appears as a numbered sub-match. Use (?:...) for non-capturing groups when you only need to group without capturing.

JavaScript also supports named capture groups using (?<name>...) syntax. For example, (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) captures year, month, and day by name. In JavaScript code, you access them as match.groups.year instead of match[1]. Named groups make complex patterns much more readable and maintainable.

What does the global (g) flag do?

Without the g flag, the regex only finds the first match. With g, it finds all non-overlapping matches in the test text. For most extraction and counting tasks, you want the g flag enabled.

Why does my regex work in the tester but not in my code?

Check the flags -- if you use g in the tester but not in your code, your code will only find the first match. Also verify the delimiters and escaping -- in many languages you need to escape backslashes in string literals (\\d instead of \d).


The short version

Regular expressions are powerful but tricky to debug. ToolHQ's regex tester lets you build and validate patterns against real test text with live highlighting -- no code writing, no context switching. Your test data never leaves your browser.

Iterate in the tester, copy the working pattern into your code.

For URL encoding/decoding, use ToolHQ's URL encoder/decoder. For JSON formatting, try the JSON formatter. Browse all developer tools at the ToolHQ developer category.

Test your regex now