Regex Tester — Live Match Highlighting

Pattern
/ /

Test String
Matches
Capture Groups
Common Patterns

What Are Regular Expressions?

A regular expression (often shortened to regex or regexp) is a pattern that describes a set of strings. Regex engines scan text character by character, checking whether the input matches the pattern. Regular expressions are one of the most powerful and widely-used tools in programming, supported natively in JavaScript, Python, Java, Go, Ruby, PHP, and virtually every other modern language.

Developers use regular expressions for a wide range of tasks: validating user input (email addresses, phone numbers, postal codes), searching and replacing text in editors and codebases, parsing log files, extracting data from unstructured text, and defining syntax highlighting rules.

Core Regex Syntax

Regular expressions are built from a few fundamental concepts:

Regex Flags

Flags modify how the regex engine processes the pattern:

Common Use Cases

Here are patterns developers frequently reach for:

Click any of the preset buttons above the tool to load these patterns with sample text and see them in action.

How to Use This Regex Tester

  1. Type your regex pattern in the pattern field between the slashes.
  2. Toggle flags (i, m, s) using the checkboxes. The global flag is always on.
  3. Enter or paste your test string in the text area below.
  4. Matches are highlighted instantly as you type. The match count updates in real time.
  5. If your pattern uses capturing groups, they appear in the Capture Groups section with each group's value.
  6. Use the preset buttons to load common patterns (email, URL, IP, hex color, date, phone) with sample text.

Frequently Asked Questions

What is a regular expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. It is used for matching, finding, and manipulating text. Regular expressions are supported in virtually every programming language and are commonly used for input validation, text search, log parsing, and data extraction.

What does the g flag do in regex?

The g (global) flag tells the regex engine to find all matches in the input string rather than stopping after the first one. This tool always applies the global flag so you can see every match highlighted simultaneously.

How do I match an email address with regex?

A common pattern is [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. This covers most real-world email addresses. Fully RFC 5322-compliant email validation is far more complex, but this pattern handles the practical cases. Click the "Email" preset button above to try it.

What's the difference between * and + in regex?

* matches zero or more occurrences — the preceding element is optional and can repeat. + matches one or more — at least one occurrence is required. For example, a* matches an empty string, but a+ does not.

What are capturing groups?

Capturing groups are portions of a regex enclosed in parentheses (). They capture the matched text so it can be referenced later — for example, in replacements or in code via match[1], match[2], etc. Named groups use the syntax (?<name>...) and can be accessed by name.

How do I escape special characters in regex?

Precede the character with a backslash: \. matches a literal period, \* matches a literal asterisk, and \\ matches a literal backslash. The special characters that require escaping are . * + ? ^ $ { } [ ] ( ) | \.

What is a lookahead in regex?

A lookahead is a zero-width assertion — it checks for a pattern without consuming characters. A positive lookahead (?=...) asserts that the pattern follows. A negative lookahead (?!...) asserts that it does not. For example, \d+(?= dollars) matches digits only when followed by " dollars", but "dollars" itself is not part of the match.