Logs
Apache Common Log Format
Parses Apache Common Log Format entries.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("^(\\S+) (\\S+) (\\S+) \\[([^\\]]+)\\] \"(\\S+) (\\S+) (\\S+)\" (\\d{3}) (\\d+|-)", "");
const input = "127.0.0.1 - frank [10/Oct/2023:13:55:36 -0700] \"GET /index.html HTTP/1.0\" 200 2326";
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"^(\\S+) (\\S+) (\\S+) \\[([^\\]]+)\\] \"(\\S+) (\\S+) (\\S+)\" (\\d{3}) (\\d+|-)")
input_text = "127.0.0.1 - frank [10/Oct/2023:13:55:36 -0700] \"GET /index.html HTTP/1.0\" 200 2326"
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(`^(\S+) (\S+) (\S+) \[([^\]]+)\] "(\S+) (\S+) (\S+)" (\d{3}) (\d+|-)`)
input := `127.0.0.1 - frank [10/Oct/2023:13:55:36 -0700] "GET /index.html HTTP/1.0" 200 2326`
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
^(\S+) (\S+) (\S+) \[([^\]]+)\] "(\S+) (\S+) (\S+)" (\d{3}) (\d+|-)Raw source: ^(\S+) (\S+) (\S+) \[([^\]]+)\] "(\S+) (\S+) (\S+)" (\d{3}) (\d+|-)
How it works
Captures 9 fields: host, ident, user, timestamp, method, path, protocol, status code, and response size.
Examples
Input
127.0.0.1 - frank [10/Oct/2023:13:55:36 -0700] "GET /index.html HTTP/1.0" 200 2326Matches
127.0.0.1 - frank [10/Oct/2023:13:55:36 -0700] "GET /index.html HTTP/1.0" 200 2326
Common use cases
- •Log analysis
- •Traffic monitoring
- •Security audits
Related patterns
Log Level
LogsMatches standard log level keywords in log lines.
Nginx Error Log
LogsParses Nginx error log lines.
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.