raatools/

Regex Tester

Test regex patterns with live matching, flags, and match details.

What are regular expressions?

Regular expressions (regex or regexp) are patterns used to match character combinations in text. They are one of the most powerful tools in programming for text search, validation, extraction, and transformation. Every major programming language supports regular expressions, and they are essential for tasks like form validation, log parsing, and data cleaning.

A regex pattern describes a set of strings using special syntax. Simple patterns match literal text, while metacharacters like . (any character), * (zero or more), and + (one or more) add flexibility. Grouping with parentheses, alternation with |, and character classes with [] let you build precise matching rules for virtually any text pattern.

How to use the regex tester

Enter a regular expression pattern in the pattern field, select your desired flags (g, i, m, s), and paste text to test against. The tool highlights all matches in real time and displays capture groups for each match. Use this to develop and debug regex patterns before embedding them in your code.

Common regex patterns

  • Email addresses: ^[^\s@]+@[^\s@]+\.[^\s@]+$ โ€” matches standard email formats.
  • URLs: https?://\S+ โ€” matches URLs starting with http or https.
  • IPv4 addresses: matches the standard dotted decimal format like 192.168.1.1 using digit quantifiers.
  • Dates: matches dates in YYYY-MM-DD format using four-digit year and two-digit month and day patterns.
  • Capitalized words: [A-Z][a-z]+ โ€” matches words starting with an uppercase letter.

Regex flags explained

  • g: g (Global): Finds all matches in the text, not just the first one.
  • i: i (Case-insensitive): Makes the pattern match regardless of letter case.
  • m: m (Multiline): Makes ^ and $ match the start and end of each line, not just the entire string.
  • s: s (Dotall): Makes the . metacharacter match newline characters as well.

Capture groups

Parentheses () create capture groups that extract specific parts of a match. Each group is numbered starting from 1. For example, the pattern (\w+)@(\w+\.\w+) applied to "user@example.com" captures "user" in group 1 and "example.com" in group 2. Named groups using (?<name>...) make complex patterns more readable.

Common regex mistakes

Forgetting to escape special characters is the most common error. Characters like . + * ? ( ) [ ] ^ $ | and curly braces have special meaning in regex and must be escaped with a backslash when you want to match them literally. For example, matching a period requires a backslash-dot instead of just a dot.

Writing overly greedy patterns is another frequent issue. The .* quantifier matches as much text as possible, which can capture far more than intended. Use the lazy quantifier .*? to match as little as possible, or use more specific patterns like [^>]* instead of .* when parsing structured text.

Frequently asked questions

Are regex patterns the same in all languages?

The core syntax is similar, but there are differences. JavaScript, Python, Java, and .NET each have slightly different features and syntax for advanced constructs like lookbehind assertions, named groups, and Unicode support. This tool uses JavaScript regex, which is the standard for web development.

How can I learn regular expressions?

Start with simple patterns and gradually add complexity. Learn the basic metacharacters (. * + ? ^ $), character classes ([a-z], \d, \w), and quantifiers first. Then move to grouping, alternation, and lookaheads. Practice with real-world tasks like validating emails, parsing log files, or extracting data from HTML.