import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "Executed\\s+as\\s+user:\\s+[\\w\\\\]+\\.|\\[SQLSTATE \\d+\\] \\(\\w+ \\d+\\)\\s*\\.?";
final String string = "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.";
final String subst = "$0\\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html