Regex Tester

Test and debug regular expressions with real-time matching and highlighting

Loading...

About Regular Expressions

Regular expressions (regex) are powerful patterns used to match, search, and manipulate text. This free regex tester helps you test and debug regular expressions with real-time matching and highlighting, making it an essential tool for developers working with pattern matching, text processing, form validation, and data extraction.

How to Use:

Enter your regular expression pattern in the regex field and your test text in the text area. The tool will highlight all matches in real-time, show match groups, and display detailed information about each match. You can test different flags (global, case-insensitive, multiline, etc.) to see how they affect matching behavior.

Basic Metacharacters:

^
Caret - Matches the start of a string
Example: ^hello matches "hello" at the start
$
Dollar - Matches the end of a string
Example: world$ matches "world" at the end
.
Dot - Matches any single character (except newline)
Example: a.c matches "abc", "a1c", "a-c"
*
Asterisk - Matches zero or more of the preceding element
Example: ab*c matches "ac", "abc", "abbc"
+
Plus - Matches one or more of the preceding element
Example: ab+c matches "abc", "abbc" (not "ac")
?
Question Mark - Matches zero or one of the preceding element
Example: colou?r matches "color" and "colour"

Character Classes & Shorthand:

\d
Digit - Matches any digit (0-9)
Example: \d3 matches "123", "456"
\w
Word Character - Matches letters, digits, and underscore
Example: \w+ matches "hello", "user123"
\s
Whitespace - Matches spaces, tabs, newlines
Example: hello\s+world matches "hello world"
[abc]
Character Class - Matches any character in brackets
Example: [aeiou] matches any vowel
[0-9]
Range - Matches characters in a range
Example: [a-z] matches any lowercase letter
(group)
Capturing Group - Captures matched text for later use
Example: (\d3)-(\d3) captures area code and number separately

Common Examples:

^\d+$
Numbers only
Matches strings containing only digits from start to end
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Email validation
Basic email address pattern (simplified)
\b\w4\b
4-letter words
Matches complete words that are exactly 4 characters long
(\d4)-(\d2)-(\d2)
Date format (YYYY-MM-DD)
Matches dates and captures year, month, and day in groups

Regex Flags:

g
Global - Find all matches, not just the first one
i
Case Insensitive - Match regardless of case (A = a)
m
Multiline - ^ and $ match line breaks, not just string boundaries
s
Dot All - . matches newline characters as well
u
Unicode - Treat pattern as a sequence of Unicode code points
y
Sticky - Matches only from the index indicated by the lastIndex property

Use Cases:

  • Form Validation: Validate email addresses, phone numbers, URLs, passwords, and other input formats
  • Text Processing: Extract, replace, or transform text patterns in documents
  • Data Parsing: Parse structured data from unstructured text (logs, CSV, etc.)
  • Search & Replace: Find and replace patterns in code editors or text processors
  • Log Analysis: Filter and extract specific information from log files
  • Code Refactoring: Find patterns in codebases for automated refactoring

Tips & Best Practices:

  • Use anchors (^ and $) when you want to match the entire string
  • Escape special characters with a backslash (\. to match a literal dot)
  • Use character classes [0-9] instead of \d if you need specific behavior
  • Test your regex with various inputs, including edge cases and empty strings
  • Use non-capturing groups (?:group) when you don't need to capture the match
  • Be mindful of regex performance with very long strings or complex patterns
  • This tool works entirely in your browser - no data is sent to servers, ensuring privacy