Skip to content

Regex Tester

Test and debug regular expressions online with real-time matching and group highlighting. Free regex tester for JavaScript and Python.

Developer Tools
Instant results
Email
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Validates email addresses

URL
^https?:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/\S*)?$

Matches URLs

Phone (US)
^\+?1?[-.]?\(?\d{3}\)?[-.]?\d{3}[-.]?\d{4}$

US phone numbers

Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$

ISO date format

Time (HH:MM)
^([01]\d|2[0-3]):[0-5]\d$

24-hour time

IPv4
^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$

IPv4 addresses

Hex Color
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$

Hex color codes

Credit Card
^\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}$

Credit card numbers

ZIP Code (US)
^\d{5}(-\d{4})?$

US ZIP codes

SSN
^\d{3}-\d{2}-\d{4}$

Social Security Number

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

Min 8 chars, mixed case, number, symbol

Username
^[a-zA-Z0-9_]{3,16}$

3-16 alphanumeric or underscore

Slug
^[a-z0-9]+(?:-[a-z0-9]+)*$

URL-friendly slug

HTML Tag
<([a-z]+)([^<]+)*(?:>(.*)|\/)(\/>|<\/\1>)

Matches HTML tags

Numbers Only
^\d+$

Only digits

Letters Only
^[a-zA-Z]+$

Only letters

How to Use Regex Tester

1

Enter your regex pattern

Type your regular expression pattern in the pattern field. Use standard JavaScript regex syntax (the same as ECMAScript).

2

Set flags

Choose flags: 'g' (global, find all matches), 'i' (case-insensitive), 'm' (multiline), 's' (dotall), 'u' (Unicode). Combine as needed.

3

Paste test text

Paste or type the text you want to test against the pattern. Matches highlight in real-time, showing exactly what your regex captures.

4

Inspect captures

Capture groups (parts in parentheses) are listed separately so you can see what each group extracted. Use this to refine patterns before using them in code.

When to Use Regex Tester

Validating user input

When building forms with regex validation (email, phone, URL, custom IDs), test patterns against various inputs first. Edge cases like international emails ('user@münchen.de'), parenthesized phone numbers, and URLs with special chars catch many naive patterns. Test thoroughly before deploying.

Search and replace operations

Before running 'find and replace with regex' across thousands of files, test the pattern on a representative sample. Verify it matches what you intend, doesn't match what you don't intend, and handles edge cases (empty matches, lazy vs greedy quantifiers). Saves hours of fixing mass-replacement mistakes.

Log file parsing

Server logs, application logs, and system logs often need regex extraction for monitoring, alerting, and analysis. Test regex against actual log samples to ensure it handles all variants — different timestamp formats, optional fields, multi-line entries, escaped special characters.

Data extraction from semi-structured text

Scraping prices from HTML, extracting dates from documents, parsing CSVs with embedded commas — regex shines when data isn't strictly structured. Test patterns interactively here to refine extraction logic before hardcoding into your application.

Regex Tester Examples

Email validation

Input
Pattern: ^[^\s@]+@[^\s@]+\.[^\s@]+$\nFlags: i\nTest: alice@example.com
Output
MATCH at position 0-19

A simple email pattern: characters before @, then @, then characters before dot, then dot, then characters until end. Real-world emails have many edge cases (international domains, +addressing, quoted local parts) — production regex should be more thorough or use a dedicated library.

Capture groups

Input
Pattern: (\d{4})-(\d{2})-(\d{2})\nTest: Today is 2026-04-26.
Output
Match: 2026-04-26\nGroup 1: 2026\nGroup 2: 04\nGroup 3: 26

Parentheses create capture groups that extract specific parts of the match. Useful for parsing structured data: date components, log fields, URL parts. Each group is accessible separately in code (match[1], match[2], etc.).

Greedy vs lazy

Input
Pattern: <.+>\nTest: <p>hello</p>
Output
Match: <p>hello</p>

Greedy quantifier (+) matches as much as possible — capturing the entire string between first < and last >. To match just the first tag <p>, use lazy quantifier: <.+?> matches '<p>'. Critical for HTML/XML parsing where you usually want the smallest match.

Tips & Best Practices for Regex Tester

  • 1.Use regex tester for development; in production, validate inputs server-side too. Client-side regex can be bypassed; server validation prevents data integrity issues regardless of how the request is made.
  • 2.Watch for catastrophic backtracking with patterns like (a+)+. Some regex inputs cause exponential time complexity, leading to DoS vulnerabilities. Test with adversarial input (long strings of similar chars) and use atomic groups or possessive quantifiers (where supported) to prevent it.
  • 3.For matching across newlines, use the 's' flag (dotall) or [\s\S] which matches any character including newlines. Default '.' doesn't match newlines.
  • 4.Use named capture groups (?<name>...) when you have multiple groups — much more readable than referring to match[1], match[2]. JavaScript and most languages support named groups.
  • 5.Comment your regex with the 'x' flag (where supported) or use a regex tool that lets you split the pattern across lines with comments. Complex regex without comments is unreadable to anyone who didn't write it (including future you).
  • 6.For very complex pattern matching, consider parser combinators or proper parsing libraries instead of regex. Regex isn't ideal for nested structures (HTML, JSON), arbitrary text formats, or context-sensitive grammars.

Frequently Asked Questions

Regex (regular expression) is a pattern that describes a set of strings. It's used for validating input like email addresses or phone numbers, searching and replacing text, parsing logs, and any other task involving text pattern matching. The syntax uses special characters (^, $, *, +, ?, [], (), |) to express patterns concisely.