const regex = /Browser((?:_type)?\s\"*)(?P<UA>(.+\"-|[^\"]+))/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Browser((?:_type)?\\s\\"*)(?P<UA>(.+\\"-|[^\\"]+))', 'g')
const str = `7 06:51:56 netscaler02 12/07/2017:12:51:56 GMT netscaler02 0-PPE-0 : AAA LOGIN_FAILED -807443279 0 : User slwagner - Client_ip 173.172.124.235 - Failure_reason "External authentication server denied access" - Browser Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3
7 06:51:56 netscaler02 12/07/2017:12:51:56 GMT netscaler02 0-PPE-0 : AAA LOGIN_FAILED -807443279 0 : User slwagner - Client_ip 173.172.124.235 - Failure_reason "External authentication server denied access" - Browser "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3"--asfashfi
`;
// 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