Regex Tester

Test and debug regular expressions with real-time matching, syntax highlighting, and detailed match information. Includes common pattern templates for emails, URLs, phone numbers, IP addresses, and more. Perfect for developers learning or debugging regex patterns.

/ /
Matches: 0
Groups: 0
Common Patterns
No matches found

How to Use This Regex Tester

  1. Enter your regex pattern: Type your regular expression in the input field between the forward slashes. Do not include the surrounding slashes yourself as they are added automatically. The pattern is validated in real-time and any syntax errors are displayed immediately.
  2. Configure regex flags: Toggle the flag buttons to modify how your pattern behaves. Click "g" for global matching (find all matches, not just the first), "i" for case-insensitive matching, "m" for multiline mode (^ and $ match line boundaries), and "s" for dotall mode (dot matches newlines).
  3. Enter test text: Type or paste the text you want to search in the test string area. Matches are highlighted automatically as you type, providing instant visual feedback on your pattern's behavior.
  4. Review highlighted results: Matched portions of your test string appear highlighted in the result area below. This visual representation helps you verify that your pattern captures exactly what you intend.
  5. Check match details: The match details section shows each match with its position in the text and any captured groups. This information is invaluable for understanding how your pattern interacts with the input.
  6. Use common patterns: Click any pattern button in the "Common Patterns" section to load pre-built regular expressions for emails, URLs, phone numbers, IP addresses, hex colors, and dates. These serve as starting points you can modify for your specific needs.

What is a Regular Expression?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Developed in the 1950s by mathematician Stephen Cole Kleene, regular expressions have become an essential tool in computing for pattern matching, text searching, and string manipulation. They provide a concise and flexible means to match strings of text based on patterns rather than fixed strings.

Regular expressions are supported in virtually every programming language including JavaScript, Python, Java, C#, PHP, Ruby, and Go. They are also built into many command-line tools like grep, sed, and awk, as well as text editors like VS Code, Sublime Text, and Vim. Learning regex is a valuable skill that transfers across languages and tools.

Common applications for regular expressions include form validation (checking email addresses, phone numbers, postal codes), search and replace operations, parsing log files, extracting data from text, and input sanitization. While regex can seem intimidating at first, mastering the basics opens up powerful text processing capabilities.

Common Regex Syntax

Character Classes: . matches any single character except newline. \d matches any digit (0-9). \w matches word characters (letters, digits, underscore). \s matches whitespace (space, tab, newline). Uppercase versions like \D, \W, \S match the opposite.

Quantifiers: * matches zero or more of the preceding element. + matches one or more. ? matches zero or one (making the preceding element optional). {n} matches exactly n times. {n,m} matches between n and m times. {n,} matches n or more times.

Anchors: ^ matches the start of a string (or line in multiline mode). $ matches the end of a string (or line). \b matches a word boundary, useful for matching whole words only.

Character Sets: [abc] matches any single character in the set (a, b, or c). [^abc] matches any character NOT in the set. [a-z] matches any lowercase letter. [A-Za-z0-9] matches any alphanumeric character.

Groups and Alternation: (pattern) creates a capturing group. (?:pattern) creates a non-capturing group. a|b matches either a or b (alternation).

Regex Flags Explained

Global (g): Without this flag, the regex stops after finding the first match. With the global flag, it continues searching and returns all matches in the string.

Case Insensitive (i): Makes the pattern match uppercase and lowercase letters interchangeably. The pattern hello would match "Hello", "HELLO", and "heLLo".

Multiline (m): Changes the behavior of ^ and $ to match the start and end of each line, not just the entire string. Essential for processing multi-line text.

Dotall (s): Makes the dot character . match newline characters as well. By default, dot matches any character except newlines.

Tips for Writing Effective Regular Expressions

Start simple and build complexity gradually. Test your pattern with various inputs including edge cases. Use non-capturing groups (?:) when you do not need to extract the matched content. Be specific rather than overly broad to avoid unexpected matches. Remember that regex is greedy by default, meaning quantifiers match as much as possible. Add ? after a quantifier to make it lazy (matching as little as possible).