Below I have a sample of a line from a log file that I have been working with for a while now:
5/21/2015 11:55:56 PM | Batch 6|386/767|50.33 %|CH2M-R|Processed NXRMN5...Checking refundable and non-refundable fares. Traditional Booking. Inside ticketing window. Minimum Savings Required: $131.00. Actual Savings: $257.18. Savings found: $257.18 (11.55 %). Savings were previously found.
In this file I have categories that I need to capture: First is the date and time, the next is the Locator which is the NXRMN5, Savings found and the percent (if any) which in this line is $257.18 11.5%.
In the Console I would want it to look like this:
Date: 5/21/2015 11:55:56 PM
Locator: NXRMN5
Dollar Savings: $257.18
Percent Savings: 11.55 %
Below I have some code that I have been working on for quite some time:
foreach (string line in gdsLines)
{
Match m = Regex.Match(line, @"Savings\s+found:\s*\$(?<savings>\d+\.\d+)\s*\(\s*(?<percent>\d+\.\d+)\s*%");
if (m.Success)
{
decimal gdsNumberSavings = decimal.Parse(m.Groups["savings"].Value, CultureInfo.InvariantCulture);
decimal gdsNumberPercent = decimal.Parse(m.Groups["percent"].Value, CultureInfo.InvariantCulture);
Console.WriteLine("Dollar Savings: $" + gdsNumberSavings + " Percent Savings: " + gdsNumberPercent + " % " + "\n");
gdsTotalSavings += gdsNumberSavings;
gdsTotalPercentage += gdsNumberPercent;
}
}
This code that I provided takes the regex I made and then puts both the savings found and the percent and then prints the values in the console. Don't worry about the gdsTotal variables that for something else. The main concern is in the regex. In order to add in the other elements that I need to, do I need to create another regex, or can I just add on to it? Either way, could someone please help me in the forming of this regex? Any help would be very appreciative!