Working in .net i'm parsing a log file where some lines do not begin with '"2018'. I need a .Match clause that will find lines where the line begins with anything except the string "2018 (note that includes the double quote). When found (and this is the tricky bit) - remove the line break from the line before the offending line. In other words, append offending lines to the line above it.
"2018-02-22 10:06:10,857","[7]"," ERROR","MyApp.Web.Infrastructure.ErrorResponseCommand","ErrorResponseCMD logs Controller: webinar | Action: Index",""
"2018-02-22 10:06:37,742","[11]"," INFO ","MyApp.Web.MvcApplication","Anon Session Starts with: {""FirstPage"": ""https://www.bankwebinars.com/wp-login.php"", ""QueryString"": """", ""SessionId"": ""uhnev2dnds33dastwrdgftvm"", ""FirstCookies"": {""CookieName"": ""ASP.NET_SessionId"", ""Value"": ""uhnev2dnds33dastwrdgftvm""}}",""
"2018-02-22 10:06:48,053","[11]"," INFO ","MyApp.Web.Controllers.CartController","SessionInfo{
""FirstPage"": null,
""RemoteAddress"": ""207.46.13.159"",
""RemoteHost"": ""207.46.13.159"",
""RemoteUser"": """",
RelativeConfirmPasswordResetUrl:Account/PasswordResetConfirm
//and other non-predictable BOL patterns.
},""
"2018-02-22 10:06:10,857","[7]"," ERROR","MyApp.Web.Infrastructure.ErrorResponseCommand","ErrorResponseCMD logs Controller: webinar | Action: Index",""
ADDENDUM: Having tried the suggested pattern - and noting that pattern works correctly for regex101's sandbox - there must be something else wrong. Here's my current code.
string str = File.ReadAllText("myLog.log");
Regex rx = new Regex("(?m)\r?\n^(?!\"2018)", RegexOptions.Singleline);
str = rx.Replace(str, "\"2018");
File.WriteAllText("test1.txt", str);
I've tried a bunch of variations on the pattern - e.g. I think the RegexOption clause is equivalent to the (?m) phrase so I've tried omitting that. Singleline should be what i want since it views the whole file as a single line but I've tried Multiline mode as well. It's a Windows file so the ? qualifier between \r and \n should not be required. None of the variations have changed the output.