Regex Tester

Test and debug regular expressions online. Real-time pattern matching with visual highlighting, capture groups, and detailed match information. Perfect for learning and validating regex patterns.

//
g - Global - find all matchesi - Case insensitivem - Multiline - ^ and $ match line boundariess - Dot all - dot matches newlinesu - Unicode - enable Unicode supporty - Sticky - match from lastIndex only

What is a Regular Expression (Regex)?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. It's used for pattern matching within strings, allowing you to find, extract, replace, or validate text based on complex rules. Regular expressions are a powerful tool in programming, text processing, and data validation.

Our regex tester helps you build and test regular expressions in real-time. You can see matches highlighted, view capture groups, test replacements, and understand how your pattern works before implementing it in code.

How to Use the Regex Tester

  1. Enter Pattern: Type your regex pattern in the top input field (without delimiters - we add them for you)
  2. Select Flags: Choose regex flags (g, i, m, etc.) by clicking the checkboxes next to the pattern
  3. Add Test String: Enter or paste the text you want to test your pattern against
  4. View Matches: See highlighted matches in real-time with detailed match information
  5. Test Replace: Optionally test regex replacement with capture group references
  6. Copy Results: Copy matches or replacement results for use in your projects

Regex Flags Explained

g - Global

Finds all matches in the text, not just the first one. Without this flag, the regex stops after finding the first match. Essential for finding multiple occurrences.

i - Case Insensitive

Makes the pattern case-insensitive. For example, /hello/i will match "Hello", "HELLO", and "hello". Useful when case doesn't matter.

m - Multiline

Makes ^ and $ match the start and end of each line, not just the start and end of the entire string. Essential for processing multi-line text.

s - Dot All

Makes the dot (.) match newline characters. By default, dot matches everything except newlines. Use this when you need to match across multiple lines.

u - Unicode

Enables full Unicode support. Allows proper handling of Unicode characters and properties. Recommended for international text processing.

y - Sticky

Makes the regex search from the exact position specified by lastIndex. Advanced flag used for specific parsing scenarios.

Common Regex Patterns

\d+

Matches one or more digits (numbers)

\w+

Matches one or more word characters (letters, digits, underscore)

\s+

Matches one or more whitespace characters (spaces, tabs, newlines)

^

Matches the start of a line

$

Matches the end of a line

.

Matches any single character (except newline by default)

*

Matches 0 or more of the preceding element

+

Matches 1 or more of the preceding element

?

Matches 0 or 1 of the preceding element (makes it optional)

[abc]

Matches any one of the characters a, b, or c

[^abc]

Matches any character except a, b, or c

(abc)

Capturing group - captures the matched text for later use

Common Use Cases

  • Email Validation: Verify email addresses follow the correct format
  • Phone Number Formatting: Extract and validate phone numbers in various formats
  • URL Extraction: Find and extract URLs from text
  • Data Validation: Ensure user input matches expected patterns (ZIP codes, dates, etc.)
  • Text Search and Replace: Find and replace complex patterns in documents
  • Log File Parsing: Extract specific information from log files
  • Code Refactoring: Find and replace code patterns across projects
  • Data Extraction: Pull specific data from HTML, CSV, or other structured text
  • Input Sanitization: Remove or replace unwanted characters from user input
  • String Manipulation: Transform text based on complex rules

Understanding Capture Groups

Capture groups are portions of your regex pattern enclosed in parentheses (). They allow you to extract specific parts of matched text and reuse them in replacements.

Basic Capture Group

Pattern: (\w+)@(\w+)\.(\w+)

Text: user@example.com

Groups:

  • Group 1: user
  • Group 2: example
  • Group 3: com

Using Groups in Replacement

Pattern: (\d{3})-(\d{3})-(\d{4})

Text: 123-456-7890

Replace with: ($1) $2-$3

Result: (123) 456-7890

FAQ

Common issues include: forgetting to escape special characters (use backslash), not selecting the right flags (especially 'g' for multiple matches or 'i' for case-insensitive), or using syntax that's not supported in JavaScript regex. Check the error message for hints.
* matches 0 or more occurrences (can match empty string), while + matches 1 or more occurrences (must match at least once). For example, a* matches "", "a", "aa", but a+ only matches "a", "aa", etc.
Use a backslash before special characters: . * + ? ^ $ { } ( ) | [ ] \. For example, to match a literal period, use \. instead of .
This tester uses JavaScript regex engine. While most regex features are similar across languages, there are differences. JavaScript regex is widely compatible, but some advanced features (like lookbehinds) may vary. For language-specific regex, check that language's documentation.
Non-capturing groups (?:...) group parts of your pattern without creating a capture group. They're useful for applying quantifiers to multiple characters without storing the match. For example, (?:abc)+ matches "abc", "abcabc", etc., without capturing.
Yes! All regex testing happens entirely in your browser. Your patterns and test strings are never sent to any server. Everything is processed locally on your device, ensuring complete privacy.

Regex Best Practices

  • Start Simple: Begin with basic patterns and add complexity gradually
  • Test Thoroughly: Use multiple test cases including edge cases
  • Be Specific: Avoid overly broad patterns that might match unintended text
  • Use Comments: In code, add comments explaining complex patterns
  • Avoid Catastrophic Backtracking: Be careful with nested quantifiers like (a+)+
  • Consider Performance: Complex regex on large texts can be slow
  • Use Anchors: Use ^ and $ when you need to match entire strings
  • Prefer Character Classes: [0-9] is often better than \d for clarity
  • Document Your Patterns: Complex regex can be hard to understand later

Usage Tips

  • Use the 'g' (global) flag to find all matches, not just the first one
  • Enable 'i' (case insensitive) flag when case doesn't matter
  • Try the quick examples to learn common regex patterns
  • Use capture groups () to extract specific parts of matches
  • Reference capture groups in replacements with $1, $2, etc.
  • The pattern is automatically surrounded by / delimiters
  • Matches are highlighted in real-time as you type
  • Copy matches or replacement results with one click
  • Check the error message if your pattern has syntax issues
  • Bookmark this tool for quick regex testing during development