Regex Named Capture Group also Include Complete String

3 days ago 2
ARTICLE AD BOX

Is it possible to have a Regex include the whole string as a named capture group as well as individual named capture groups?

I am trying to parse IIS logs and can successfully extract the details I require using named capture groups using the following regex:

^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (?<s_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) (?<method>\w{3,4}) \S+ \S+ (?<s_port>\d{1,5}) \S+ (?<c_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) \S+ \S+ (?<status>\d{3}) \d+ \d+ (?<duration>\d+)$

The following is am example of the IIS log:

2026-03-06 19:20:09 10.10.10.10 GET /api/dhs/critical token=1234567890l&server=A 800 - 192.168.0.1 - - 200 0 0 16

In addition to time, s_ip, method, s_port, c_ip, status & duration, I would like to have say message that is the whole log line.

Read Entire Article