Matching given strings to set patterns and extracting the data.
Hi All.
To explain, I am a creating a feature that uses an external program which produces log files that I have no control over. I need to use these log files to produce a report.
The log files have limited outputs and I have a list of all the different log message patterns and I want to extract information where the curly brackets are.
For example, here are 4 different log message patterns:
1. DEBUG:root:{TestHeader}
2. DEBUG:root:{TestName}; Correct {Result}; on input {Input}. Expected {Expected} and got {Got}
3. DEBUG:root:{TestName}; Correct {Result}; got {Got} and expected {Expected}
I take in the log files and seperate them to get strings such as:
1. DEBUG:root:Testing materials
This string should match log pattern 1 and I want to extract "Testing materials".
2. DEBUG:root:testForMetal; Correct True; on input Copper. Expected Metal and got Metal
This string should match log pattern 2 and I want to extract "testForMetal", "Copper", "Metal" and "Metal" respectively into variables TestName, Correct, Expected and Got.
I have not dealt with anything like this before, could anybody lead me in the correct direction for creating a solution please?
2 Replies
Look at RegEx and matching Groups
I have looked at this and it seems to make sense for what I need, thank you. https://stackoverflow.com/a/38722327
Stack Overflow
Get string value from Placeholder C#
I have pattern string:"Hello {Name}, welcome to {Country}"
and a full value string:"Hello Scott, welcome to VietNam"
How can I extract value of {Name} and {Country}:
Name = Scott, Country = VietNam
I