When troubleshooting regular expressions against multi-line telemetry or access logs, subtle anchor or quantifier mistakes often cause silent non-matches or shifted numbered groups. Consider two structured application log lines containing ISO-8601 timestamps, severity tags, service identifiers, 16-hex-character trace IDs, HTTP status codes, and floating-point latencies:
2026-11-01T14:22:08.419Z [ERROR] svc=checkout trace_id=4bf92f3577b34da6 status=502 latency_ms=184.7
2026-11-01T14:22:09.004Z [INFO] svc=inventory trace_id=00f067aa0ba902b7 status=200 latency_ms=12.3
To parse every line deterministically without fragile positional array indexing, bind each field with an ECMAScript named capture group ((?<name>...)), wrap the optional fractional millisecond suffix in a non-capturing group ((?:...)), and enable both g (global iteration) and m (per-line ^ and $ anchors):
^(?<ts>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)\s+\[(?<level>ERROR|WARN|INFO)\]\s+svc=(?<service>[a-z0-9_-]+)\s+trace_id=(?<trace>[0-9a-f]{16})\s+status=(?<status>\d{3})\s+latency_ms=(?<ms>\d+(?:\.\d+)?)$
Without the m flag, ^ and $ anchor exclusively to index 0 and the end of the entire buffer, causing the expression to fail as soon as a newline (\n) separates records. With gm active, the capture group debugger resolves each match iteration into both 1-based positional submatches and a structured groups object:
{
"matchIndex": 0,
"span": [0, 99],
"fullMatch": "2026-11-01T14:22:08.419Z [ERROR] svc=checkout trace_id=4bf92f3577b34da6 status=502 latency_ms=184.7",
"captures": [
"2026-11-01T14:22:08.419Z",
"ERROR",
"checkout",
"4bf92f3577b34da6",
"502",
"184.7"
],
"groups": {
"ts": "2026-11-01T14:22:08.419Z",
"level": "ERROR",
"service": "checkout",
"trace": "4bf92f3577b34da6",
"status": "502",
"ms": "184.7"
}
}
Once capture boundaries are verified, you can test String.prototype.replaceAll formatting directly in the substitution panel. Supplying the template [$<level>] $<service>: HTTP $<status> ($<ms>ms, trace=$<trace>) produces normalized output immediately:
[ERROR] checkout: HTTP 502 (184.7ms, trace=4bf92f3577b34da6)
[INFO] inventory: HTTP 200 (12.3ms, trace=00f067aa0ba902b7)