const regex = /^(?<hostip>[^ ]+) - - \[(?<timestamp>[^ ]+)\s-(?<unknown1>\d+)] "(?<method>[^ ]+) (?<request>[^ ]+) HTTP\/\d\.\d" (?<response>\d+) - (?<bytes>\d+)/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?<hostip>[^ ]+) - - \\[(?<timestamp>[^ ]+)\\s-(?<unknown1>\\d+)] "(?<method>[^ ]+) (?<request>[^ ]+) HTTP\\\/\\d\\.\\d" (?<response>\\d+) - (?<bytes>\\d+)', '')
const str = `10.170.63.247 - - [16/Jun/2015:10:25:56 -0400] "GET /iconic/staticContentBuild/js/jquery-1.8.2.js HTTP/1.1" 200 - 580 SMUSER=- remote-client-ip=10.29.110.51 http_referer=- Agent=Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257
10.170.63.247 - - [16/Jun/2015:10:25:56 -0400] "GET /retail/staticContentBuild/js/pos-module.js HTTP/1.1" 200 - 120 SMUSER=- remote-client-ip=10.164.96.28 http_referer=- Agent=Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)
10.170.63.247 - - [16/Jun/2015:10:25:56 -0400] "GET /retail/mobilepos/screens/ETR2/styles/omnilink.css HTTP/1.1" 200 - 170 SMUSER=- remote-client-ip=10.27.174.140 http_referer=- Agent=Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257
10.170.63.247 - - [16/Jun/2015:10:25:57 -0400] "GET /retail/staticContentBuild/images/queue_icon_greyw.png HTTP/1.1" 200 - 230 SMUSER=- remote-client-ip=10.167.154.165 http_referer=- Agent=Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Tablet PC 2.0; .NET CLR 1.1.4322)
10.170.63.247 - - [16/Jun/2015:10:25:57 -0400] "GET /retail/staticContentBuild/js/handlebar-data.js HTTP/1.1" 200 - 140 SMUSER=- remote-client-ip=10.166.12.56 http_referer=- Agent=Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257
10.144.62.247 - - [16/Jun/2015:10:25:57 -0400] "GET /retail/mobilepos/screens/ETR2/scripts/templates/device-details/modals/reset-voicemail-password/resetVoicemailPasswordItemView.tmpl HTTP/1.1" 200 - 180 SMUSER=- remote-client-ip=10.130.4.66 http_referer=- Agent=Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257
10.170.63.247 - - [16/Jun/2015:10:25:57 -0400] "GET /iconic/staticContentBuild/js/accountLines.js HTTP/1.1" 200 - 240 SMUSER=- remote-client-ip=10.164.18.46 http_referer=- Agent=Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions