ToolRun
🔍

Regex Tester

Test and debug regular expressions with real-time match highlighting, capture groups, and match details.

Regex Tester

Test regular expressions against sample text with real-time match highlighting.

Highlighted Matches

Contact us at [email protected] or [email protected] for help.

2 matches found

About Regular Expressions

Regular expressions (regex or regexp) are powerful patterns used to match, search, and manipulate text. They are supported in virtually every programming language and many command-line tools. While the syntax can seem intimidating at first, understanding the basics unlocks a powerful tool for text processing.

Common Regex Patterns

Here are some frequently used patterns:

  • Email: \b[\w.-]+@[\w.-]+\.\w{2,}\b
  • URL: https?://[\w.-]+(?:\.[\w]{2,})(?:/[\w./-]*)*
  • Phone (US): \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
  • IP Address (v4): \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
  • Date (YYYY-MM-DD): \d{4}-\d{2}-\d{2}
  • Hex Color: #[0-9a-fA-F]{3,8}

Regex Syntax Quick Reference

  • . matches any character except newline
  • \d matches any digit (0-9), \D matches non-digits
  • \w matches word characters (letters, digits, underscore), \W matches non-word characters
  • \s matches whitespace, \S matches non-whitespace
  • * zero or more, + one or more, ? zero or one
  • {n,m} between n and m occurrences
  • [abc] character class, [^abc] negated class
  • ^ start of string, $ end of string
  • (group) capturing group, (?:group) non-capturing
  • \b word boundary

Regex Flags

  • g (global): Find all matches, not just the first
  • i (case-insensitive): Ignore uppercase/lowercase differences
  • m (multiline): ^ and $ match start/end of each line, not just the string
  • s (dotAll): Makes . match newline characters too
  • u (unicode): Treat pattern as a sequence of Unicode code points

Frequently Asked Questions

What is the difference between .* and .*? in regex?
.* is a greedy quantifier that matches as many characters as possible. .*? is lazy (non-greedy) and matches as few characters as possible. For example, given the text "<b>bold</b>", the pattern <.*> matches the entire string (greedy), while <.*?> matches just "<b>" and "</b>" separately (lazy). Use lazy quantifiers when you want the shortest possible match.
How do capturing groups work?
Parentheses () create capturing groups that save the matched text for later reference. For example, the pattern (\d{4})-(\d{2})-(\d{2}) matching "2024-01-15" captures three groups: $1="2024", $2="01", $3="15". Groups are numbered from left to right by their opening parenthesis. Use (?:...) for grouping without capturing when you do not need the matched text.
Why does my regex work in one language but not another?
Different regex engines (PCRE, JavaScript, Python, Java, etc.) support different features. For example, lookbehind assertions with variable length work in JavaScript and .NET but not in all PCRE implementations. Named groups use different syntax: (?P<name>...) in Python vs (?<name>...) in JavaScript. This tool uses the JavaScript regex engine. Always check the documentation for your specific language.
How can I match text across multiple lines?
By default, the . character does not match newline characters (\n). Use the s flag (dotAll) to make . match everything including newlines. Alternatively, use [\s\S] to match any character including newlines without the s flag. For matching at the start/end of individual lines, use the m (multiline) flag so that ^ and $ match line boundaries, not just the start and end of the entire string.

Related Tools