Logsflags: g
Log4j Pattern Layout Token
Match Log4j / Logback PatternLayout conversion specifiers like `%d{yyyy-MM-dd}`, `%-5p`, or `%c{1}`.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("%(?:-?\\d+)?(?:\\.\\d+)?[a-zA-Z](?:\\{[^}]*\\})?", "g");
const input = "%d{yyyy-MM-dd HH:mm:ss} [%-5p] %c{1} - %m%n";
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
pyPython
import re
pattern = re.compile(r"%(?:-?\d+)?(?:\.\d+)?[a-zA-Z](?:\{[^}]*\})?")
input_text = "%d{yyyy-MM-dd HH:mm:ss} [%-5p] %c{1} - %m%n"
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
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`%(?:-?\d+)?(?:\.\d+)?[a-zA-Z](?:\{[^}]*\})?`)
input := `%d{yyyy-MM-dd HH:mm:ss} [%-5p] %c{1} - %m%n`
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
regexengine-agnostic
%(?:-?\d+)?(?:\.\d+)?[a-zA-Z](?:\{[^}]*\})? (flags: g)Raw source: %(?:-?\d+)?(?:\.\d+)?[a-zA-Z](?:\{[^}]*\})?
How it works
% starts a conversion specifier. (?:-?\d+)? optionally matches a width modifier (negative for left-justify). (?:\.\d+)? optionally matches a max-width. [a-zA-Z] captures the conversion letter (d=date, p=priority, c=category, m=message, n=newline, etc.). (?:\{[^}]*\})? optionally matches a parameter in braces.
Examples
Input
%d{yyyy-MM-dd HH:mm:ss} [%-5p] %c{1} - %m%nMatches
%d{yyyy-MM-dd HH:mm:ss}%-5p%c{1}%m%n
Input
%t %pMatches
%t%p
Input
no log4j tokensNo match
—Common use cases
- •Migrating Log4j config to logback / slf4j
- •Building config UIs for Java logging
- •Documenting custom layouts
- •Detecting deprecated specifiers in CI
Related patterns
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.
Apache Common Log Format
LogsParses Apache Common Log Format entries.
Java Stack Trace Line
LogsMatches a single Java stack trace frame line.