Apache User Agent Regex Generator
Generate named capture groups for Apache access logs where user agent matters locally in the browser.
198.51.100.6 - - [27/Apr/2026:12:15:12 +0000] "GET /docs HTTP/1.1" 200 1024 "-" "Mozilla/5.0 (Macintosh)"
Generate named capture groups for Apache access logs where user agent matters locally in the browser.
此工具在你的浏览器本地运行。你的输入不会被上传。
Copy the generated result or open the full tool to adjust inputs locally.
198.51.100.6 - - [27/Apr/2026:12:15:12 +0000] "GET /docs HTTP/1.1" 200 1024 "-" "Mozilla/5.0 (Macintosh)"
JavaScript regex
/^(?<ip>\S+)\s+\S+\s+\S+\s+\[(?<timestamp>[^\]]+)\]\s+"(?<method>[A-Z]+)\s+(?<path>\S+)\s+HTTP\/[\d.]+"\s+(?<status>\d{3})\s+\S+(?:\s+"[^"]*")?(?:\s+"(?<userAgent>[^"]*)")?.*$/m
Python regex
r"^(?P<ip>\\S+)\\s+\\S+\\s+\\S+\\s+\\[(?P<timestamp>[^\\]]+)\\]\\s+\"(?P<method>[A-Z]+)\\s+(?P<path>\\S+)\\s+HTTP\\/[\\d.]+\"\\s+(?P<status>\\d{3})\\s+\\S+(?:\\s+\"[^\"]*\")?(?:\\s+\"(?P<userAgent>[^\"]*)\")?.*$"
Field table
| Field | Capture group |
| --- | --- |
| ip | `ip` |
| timestamp | `timestamp` |
| method | `method` |
| path | `path` |
| status | `status` |
| userAgent | `userAgent` |
Preview
Line 1: matched (ip=198.51.100.6, timestamp=27/Apr/2026:12:15:12 +0000, method=GET, path=/docs, status=200, userAgent=Mozilla/5.0 (Macintosh))
Python snippet
import re
pattern = re.compile(r"^(?P<ip>\\S+)\\s+\\S+\\s+\\S+\\s+\\[(?P<timestamp>[^\\]]+)\\]\\s+\"(?P<method>[A-Z]+)\\s+(?P<path>\\S+)\\s+HTTP\\/[\\d.]+\"\\s+(?P<status>\\d{3})\\s+\\S+(?:\\s+\"[^\"]*\")?(?:\\s+\"(?P<userAgent>[^\"]*)\")?.*$")
match = pattern.search(line)
if match:
fields = match.groupdict()
JavaScript snippet
const pattern = /^(?<ip>\S+)\s+\S+\s+\S+\s+\[(?<timestamp>[^\]]+)\]\s+"(?<method>[A-Z]+)\s+(?<path>\S+)\s+HTTP\\/[\d.]+"\s+(?<status>\d{3})\s+\S+(?:\s+"[^"]*")?(?:\s+"(?<userAgent>[^"]*)")?.*$/m;
const match = line.match(pattern);
const fields = match?.groups ?? {};Generate named capture groups for Apache access logs where user agent matters locally in the browser.
198.51.100.6 - - [27/Apr/2026:12:15:12 +0000] "GET /docs HTTP/1.1" 200 1024 "-" "Mozilla/5.0 (Macintosh)"
No. It generates a practical starter for common formats and shows warnings when manual adjustment is likely.
No. Generation and preview run locally in the browser.
Named groups make downstream parsing clearer because each extracted value is labeled by field name.