Log Level
Matches standard log level keywords in log lines.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\\b", "g");
const input = "[INFO] Server started. [ERROR] Connection failed.";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b")
input_text = "[INFO] Server started. [ERROR] Connection failed."
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b`)
input := `[INFO] Server started. [ERROR] Connection failed.`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
\b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b (flags: g)Raw source: \b(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b
How it works
Examples
Input
[INFO] Server started. [ERROR] Connection failed.Matches
INFOERROR
Input
DEBUG: cache missMatches
DEBUG
Common use cases
- •Log filtering
- •Alerting
- •Error triage
Related patterns
Nginx Error Log
LogsParses Nginx error log lines.
Apache Common Log Format
LogsParses Apache Common Log Format entries.
CloudWatch Log Stream Path
LogsMatch AWS CloudWatch log group / stream paths like `/aws/lambda/my-function` or `/aws/ecs/cluster-name`.
JSON Log Line (Single-Line Object)
LogsMatch a single-line JSON object — typical of structured logging from services like slog, Bunyan, or Pino.
Related concepts
Alternation with the | Operator
ConceptThe pipe | matches either the expression on its left or on its right. Combine with groups to alternate over a subpattern.
How to Match Multiple Patterns (Alternation)
How-toCombine patterns with | to match either option. Wrap alternatives in a group to scope the alternation correctly.