const regex = /Executed\s+as\s+user:\s+[\w\\]+\.|\[SQLSTATE \d+\] \(\w+ \d+\)\s*\.?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Executed\\s+as\\s+user:\\s+[\\w\\\\]+\\.|\\[SQLSTATE \\d+\\] \\(\\w+ \\d+\\)\\s*\\.?', 'gm')
const str = `Executed as user: Company\\SA_SQLA. Warning: Null value is eliminated by an aggregate or other SET operation. [SQLSTATE 01003] (Message 8153) Warning: Null value is eliminated by an aggregate or other SET operation. [SQLSTATE 01003] (Message 8153) Warning: Null value is eliminated by an aggregate or other SET operation. [SQLSTATE 01003] (Message 8153) Warning: Null value is eliminated by an aggregate or other SET operation. [SQLSTATE 01003] (Message 8153) The OLE DB provider "MSOLEDBSQL" for linked server "linked_server" does not contain the table ""databasename"."dbo"."table"". The table either does not exist or the current user does not have permissions on that table. [SQLSTATE 42000] (Error 7314) 2023-04-04 08:19:05.797: Fetching data, please wait... [SQLSTATE 01000] (Error 50000) 2023-04-04 08:19:05.797: Fetching data for Mar 4 2023 8:19AM, please wait... [SQLSTATE 01000] (Error 50000) 2023-04-04 08:20:07.813: Fetching data done! Starting Calculation, please wait... [SQLSTATE 01000] (Error 50000) 2023-04-04 08:20:22.657: Calculation Done! forwarding data, please wait... [SQLSTATE 01000] (Error 50000). The step failed.`;
const subst = `$0\n`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
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