const regex = /^(?P<date>[^\s]+)\s+(?P<time>[^\s]+)\s+(?P<time_taken>[^\s]+)\s+(?P<c_ip>[^\s]+)\s+(?P<cs_username>[^\s]+)\s+(?P<cs_auth_group>[^\s]+)\s+(?P<x_exception_id>[^\s]+)\s+(?P<filter_result>[^\s]+).*?\"(?P<category>[^\"]+)\"\s+(?P<http_referrer>[^\s]+)\s+(?P<sc_status>[^\s]+)\s+(?P<action>[^\s]+)\s+(?P<cs_method>[^\s]+)\s+(?P<http_content_type>[^\s]+)\s+(?P<cs_uri_scheme>[^\s]+)\s+(?P<cs_host>[^\s]+)\s+(?P<cs_uri_port>[^\s]+)\s+(?P<cs_uri_path>[^\s]+)\s+(?P<cs_uri_query>[^\s]+)\s+(?P<cs_uri_extension>[^\s]+)\s+\"(?P<http_user_agent>[^\"]+)\"\s+(?P<s_ip>[^\s]+)\s+(?P<sc_bytes>[^\s]+)\s+(?P<cs_bytes>[^\s]+)\s+\"?(?P<x_virus_id>[^\"]+)\"?\s+\"(?P<x_bluecoat_application_name>[^\"]+)\"\s+\"(?P<x_bluecoat_application_operation>[^\"]+)\"/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?P<date>[^\\s]+)\\s+(?P<time>[^\\s]+)\\s+(?P<time_taken>[^\\s]+)\\s+(?P<c_ip>[^\\s]+)\\s+(?P<cs_username>[^\\s]+)\\s+(?P<cs_auth_group>[^\\s]+)\\s+(?P<x_exception_id>[^\\s]+)\\s+(?P<filter_result>[^\\s]+).*?\\"(?P<category>[^\\"]+)\\"\\s+(?P<http_referrer>[^\\s]+)\\s+(?P<sc_status>[^\\s]+)\\s+(?P<action>[^\\s]+)\\s+(?P<cs_method>[^\\s]+)\\s+(?P<http_content_type>[^\\s]+)\\s+(?P<cs_uri_scheme>[^\\s]+)\\s+(?P<cs_host>[^\\s]+)\\s+(?P<cs_uri_port>[^\\s]+)\\s+(?P<cs_uri_path>[^\\s]+)\\s+(?P<cs_uri_query>[^\\s]+)\\s+(?P<cs_uri_extension>[^\\s]+)\\s+\\"(?P<http_user_agent>[^\\"]+)\\"\\s+(?P<s_ip>[^\\s]+)\\s+(?P<sc_bytes>[^\\s]+)\\s+(?P<cs_bytes>[^\\s]+)\\s+\\"?(?P<x_virus_id>[^\\"]+)\\"?\\s+\\"(?P<x_bluecoat_application_name>[^\\"]+)\\"\\s+\\"(?P<x_bluecoat_application_operation>[^\\"]+)\\"', 'gm')
const str = `
2015-11-05 16:01:53 54 10.0.19.44 hammlx1 - - OBSERVED "Web Ads/Analytics" http://bcp.crwdcntrl.net/5/c=1226/rand=328960996/pv=y/int=%23OpR%2358075%23DailyMail%20%3A%20Time%20of%20Day%20%3A%2010AM%C2%A0/int=%23OpR%2358689%23Dailymail%20%3A%20Weather-current-description%20%3A%20Cloudy%20with%20outbreaks%20of%20Rain/int=%23OpR%2358690%23Dailymail%20%3A%20Weather-current-temperature%20%3A%2043%C2%B0F/int=%23OpR%2358691%23Dailymail%20%3A%20Weather-upcoming-description%20%3A%20Scattered%20Showers/int=%23OpR%2358692%23Dailymail%20%3A%20Weather-upcoming-temperature%20%3A%2046%C2%B0F/med=%23OpR%2350629%23DailyMail%20%3A%20Home%20Page%20Date%20%3A%20Thursday%2C%20Nov%205th%202015/seg=%23OpR%2350561%23Date%20%3A%20Thursday%2C%20Nov%205th%202015/ug=%23OpR%2350557%23GrapeShot%20%3A%20Channel%20%3A%20gv_weightwatchers/ug=%23OpR%2350558%23GrapeShot%20%3A%20Channel%20%3A%20gv_weightwatchers/ug=%23OpR%2350559%23GrapeShot%20%3A%20US%20Channel%20%3A%20us_negative_crime/ug=%23OpR%2350560%23GrapeShot%20%3A%20US%20Channel%20%3A%20us_negative_crime/genp=%23OpR%2330426%23Site%20Section%20%3A%20index/genp=%23OpR%2330427%23Site%20Section%20%3A%20ushome/rt=ifr 204 TCP_NC_MISS GET image/png;charset=UTF-8 http su.addthis.com 80 /red/usync ?pid=11127&puid=ce5754badf674f9ba73d138adc3e8e1a - "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" 10.0.2.248 451 2394 - "none" "none"
2015-11-05 16:05:14 763 10.80.64.129 cajones - us-ads.openx.net 173.241.244.221 None - - PROXIED "Web Ads/Analytics" http://lagrangenews.com/news/5895/students-strive-to-serve 200 TCP_NC_MISS GET application/json http us-ads.openx.net 80 /w/1.0/acj ?o=5040266117&callback=OX_5040266117&ju=http%3A//lagrangenews.com/news/5895/students-strive-to-serve&jr=http%3A//lagrangenews.com/&auid=538038002&dims=1419x731&adxy=0%2C0&res=1440x900x32&plg=pm&ch=utf-8&tz=300&ws=1419x731&ifr=0&tws=1419x731&vmt=1&bi=66daec33-f482-4821-b52e-7f07e884dfe3&sd=29 - "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; Media Center PC 6.0; BRI/2)" 10.75.95.91 1906 2550 - "none" "none" none`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// 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