Regex Tester

Test regular expressions with live match highlighting and capture group display. Supports all JavaScript regex flags.

/ / gi
Ad

How to Use the Regex Tester

  1. Enter your regex pattern in the pattern input field (without the surrounding slashes).
  2. Select flags using the checkboxes: g (global), i (case-insensitive), m (multiline), s (dotAll), u (unicode).
  3. Type or paste test text into the test string area. Matches are highlighted in real time.
  4. View the match details below, including match positions and capture groups.
  5. Use the common patterns buttons to quickly insert popular regex patterns.

About Regular Expressions

Regular expressions (regex or regexp) are powerful patterns used to match character combinations in strings. They are a fundamental tool in programming, used for input validation, search and replace, text parsing, and data extraction. Every major programming language supports regex, though syntax details may vary slightly between implementations.

This tool uses JavaScript's built-in RegExp engine, which supports the ECMAScript standard. Common regex constructs include character classes ([a-z]), quantifiers (+, *, ?), anchors (^ and $), groups and capturing (parentheses), lookahead and lookbehind, and alternation (|). Mastering regex is an essential skill for developers, data engineers, and system administrators working with text processing tasks.

Common Regex Patterns

These are the most frequently needed regex patterns in web development. Copy them and paste into the pattern field above to test them against your own data.

Email Address

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

Matches: [email protected], [email protected]
Misses:  @invalid, user@, [email protected]

URL (HTTP/HTTPS)

https?://[\w\-._~:/?#\[\]@!$&'()*+,;=%]+

Matches: https://example.com/path?q=test
         http://sub.domain.com:8080/page

Phone Number (International)

\+?[\d\s\-().]{7,15}

Matches: +1 (555) 123-4567, 555-1234, +44 20 7946 0958

IPv4 Address

\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b

Matches: 192.168.1.1, 10.0.0.1, 255.255.255.0

Date (YYYY-MM-DD)

\b\d{4}[-/]\d{2}[-/]\d{2}\b

Matches: 2026-02-17, 2025/12/31

Strong Password Validation

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

Requires: 8+ chars, uppercase, lowercase, digit, special character

Regex Cheat Sheet

Quick reference for the most commonly used regex syntax elements. Bookmark this page for fast lookup while writing patterns.

Pattern Meaning Example
.Any character (except newline)a.c matches "abc", "a1c"
\dAny digit [0-9]\d{3} matches "123"
\wWord character [a-zA-Z0-9_]\w+ matches "hello_123"
\sWhitespace character\s+ matches spaces/tabs
^Start of string/line^Hello matches "Hello world"
$End of string/lineend$ matches "the end"
*0 or more timesab*c matches "ac", "abc", "abbc"
+1 or more timesab+c matches "abc", "abbc"
?0 or 1 time (optional)colou?r matches "color", "colour"
{n,m}Between n and m times\d{2,4} matches "12", "123", "1234"
[abc]Character class (a, b, or c)[aeiou] matches any vowel
(abc)Capture group(\d+)-(\d+) captures "123" and "456"
a|bAlternation (a or b)cat|dog matches "cat" or "dog"
(?=...)Positive lookahead\d+(?=px) matches "12" in "12px"
(?!...)Negative lookahead\d+(?!px) matches "12" not before "px"

Why Regular Expressions Are Essential for Developers

Regular expressions are one of the most powerful tools in a developer's toolkit, yet they are also one of the most frequently misunderstood. At their core, regex patterns describe text structures using a concise formal language. This makes them invaluable for tasks that would otherwise require dozens of lines of procedural string-processing code: validating input formats, extracting data from logs, transforming text, and enforcing patterns in configuration files.

In web development specifically, regex appears everywhere. Form validation uses patterns to check email addresses, phone numbers, postal codes, and passwords. Server-side routing maps URL patterns to handlers. Log analysis tools use regex to parse timestamps, IP addresses, and error codes from massive log files. Find-and-replace operations in code editors rely on regex for refactoring across thousands of files. Build tools use regex to transform, bundle, and minify source code.

The key to mastering regex is understanding that it operates on a different level of abstraction than imperative code. Instead of telling the computer how to search step by step, you describe what you are looking for. This declarative approach can be incredibly concise but also opaque if you are not fluent in the syntax. That is why tools like this regex tester on Toolsium are so valuable: they let you experiment with patterns, see matches in real time, and inspect capture groups before embedding the pattern in your production code.

Frequently Asked Questions

A regular expression (regex) is a sequence of characters that defines a search pattern. It is used to match, find, and manipulate text. Regex is supported in virtually every programming language and is essential for input validation, text parsing, and search-and-replace operations.

Regex flags modify how the pattern matching works. Common flags include: g (global, find all matches), i (case-insensitive matching), m (multiline, ^ and $ match line boundaries), s (dotAll, dot matches newlines), and u (unicode, enables full Unicode support).

Capture groups are portions of a regex pattern enclosed in parentheses (). They allow you to extract specific parts of a match. For example, the pattern (\d{3})-(\d{4}) matching "555-1234" would capture "555" as group 1 and "1234" as group 2.

Greedy quantifiers (*, +, ?) match as much text as possible. Lazy quantifiers (*?, +?, ??) match as little text as possible. For example, given the HTML <b>bold</b>, the greedy pattern <.*> matches the entire string, while the lazy <.*?> matches just <b>.

A lookahead is a zero-width assertion that checks if a pattern follows the current position without including it in the match. Positive lookahead (?=...) asserts the pattern is ahead. Negative lookahead (?!...) asserts the pattern is NOT ahead. For example, \d+(?= dollars) matches numbers only when followed by " dollars".

Special regex characters like . * + ? [ ] ( ) { } ^ $ | \ must be escaped with a backslash to match them literally. For example, use \. to match a literal period, \$ to match a dollar sign, and \( to match an opening parenthesis.

If your regex matches too much, try using a lazy quantifier (add ? after * or +) or a more specific character class instead of the dot wildcard. If it matches too little, check that the global flag (g) is enabled, your anchors are correct, and the multiline flag (m) is set if needed.

Yes, modern JavaScript (ES2018+) supports named capture groups with the syntax (?<name>...). For example, (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) creates named groups accessible via match.groups.year and so on.