Skip to content

Pattern Matching

Use ~ to match a value against a regular expression, and !~ to negate the match:

message~"error.*timeout"
path!~"^/health"
OperatorMeaning
~Value matches regex pattern
!~Value does not match regex pattern

The regex syntax depends on the target backend:

  • ClickHouse — uses match() function (RE2 syntax)
  • PostgreSQL — uses ~ and !~ operators (POSIX regex)
  • StarRocks — uses regexp function
  • In-memory matcher — uses the host language’s regex engine (Go regexp, Python re2, JS RegExp)

Quote the pattern when it contains spaces or special characters:

message~"connection (refused|reset)"
host~"^prod-[0-9]+"

To perform case-insensitive regex matching, use the (?i) flag at the start of your pattern:

message~"(?i)error"
level~"(?i)^(warn|error|fatal)$"

The (?i) inline flag is a regex feature — support varies by backend:

Backend(?i) supportNotes
ClickHouseYesRE2 syntax
PostgreSQLYesPOSIX regex
StarRocksYesRE2 syntax
Go in-memory matcherYesGo regexp (RE2)
Python in-memory matcherYesgoogle-re2
JavaScript in-memory matcherNoECMAScript RegExp does not support (?i) inline flags

For the JavaScript in-memory matcher, use a character-class approach instead to achieve case-insensitive matching:

message~"[eE][rR][rR][oO][rR]"

Or, when targeting SQL backends only, (?i) works reliably across all three dialects.

Combine case-insensitive matching with negation to exclude patterns regardless of case:

message~"(?i)error" and message!~"(?i)warning"

Use * at the end of an unquoted value for glob-style prefix matching:

host=prod*
service=api-*

This matches any value that starts with the given prefix. Wildcards are only supported at the end of a value — *prod or pr*od are not supported.

PatternSyntaxExample
Wildcard (prefix)key=value*host=prod*
Regex (full)key~"pattern"host~"^prod-[0-9]+"

Use wildcards for simple prefix matching. Use regex when you need more complex patterns.

# Regex: messages containing "error" or "fail"
message~"error|fail"
# Regex: paths starting with /api/v2
path~"^/api/v2"
# Negated regex: exclude health check paths
path!~"^/health"
# Wildcard: hosts starting with "prod"
host=prod*
# Combined
host=prod* and message~"timeout.*" and path!~"^/health"