Skip to main content
Prabhava Groups

Regex Tester

Test JavaScript regular expressions in real-time with visual match highlighting, capture group extraction, string replacement preview, and common DevOps regex presets.

Common Presets
Flags:
Match Highlighting 0 matches

Capture Groups & Match Details

Matches and capture groups will appear here.

Replacement Preview

Understanding regular expressions

Regular expressions (regex) define search patterns for parsing, validating, and transforming strings. In software development and DevOps automation, regex powers log filtering in tools like grep and Promtail, route matching in Nginx, and format validation in input schemas.

Patterns combine literal characters with specialized metacharacters. For example, \d matches any numeric digit, + matches one or more repetitions, and brackets like [a-z] denote custom character sets.

Understanding regex flags

Flags alter how the regular expression engine interprets the pattern:

  • g (global): Continues scanning across the whole input string rather than terminating upon finding the initial match.
  • i (case-insensitive): Treats uppercase and lowercase letters interchangeably, matching "Error" and "error".
  • m (multiline): Treats boundary anchors ^ and $ as matching line starts and line ends rather than the document boundary.
  • s (dotAll): Allows the period . to match newline characters, simplifying multi-line log parsing.
  • u (unicode): Enables full Unicode code-point matching and surrogate pair support.

Worked examples

  • IPv4 validation: Validating dotted-decimal IP addresses to ensure each octet falls strictly between 0 and 255.
  • Log timestamp parsing: Isolating ISO 8601 dates (YYYY-MM-DD) in application stdout logs using capture groups.
  • Secret redaction: Finding sensitive patterns like bearer tokens or API keys and substituting them with [REDACTED] before persisting logs.

Common mistakes

  • Catastrophic backtracking: Nesting quantifiers like (a+)+ can cause exponential regex engine evaluation, freezing applications.
  • Forgetting to escape dots: An unescaped period . matches any character. In domain names or IP addresses, write \..
  • Unanchored validation: Omitting start ^ and end $ anchors allows invalid strings containing valid substrings to pass validation.

Frequently asked questions

What does the global (g) flag do in regular expressions?

Without the "g" flag, a regex engine stops immediately after finding the first match. Enabling the global flag instructs the engine to scan the entire string and return all occurrences.

What is the difference between multiline (m) and dotAll (s) flags?

The multiline flag ("m") causes "^" and "$" to match the beginning and end of every line rather than the whole string. The dotAll flag ("s") allows the wildcard dot "." to match newline characters.

How do named capture groups work?

Using the syntax (?<name>pattern), you assign labels to matched substrings. These labels appear in match results, making code clearer than accessing numbered indices like $1 or $2.

How do I reference capture groups during text replacement?

In replacement patterns, write $1, $2, etc., to insert numbered groups, or $<name> for named groups. Writing "$&" inserts the entire matched substring.

Is my test text processed on a server?

No. The regex engine runs entirely in your local browser using JavaScript's native RegExp engine. Your sensitive logs, tokens, and payloads never leave your computer.