I've been battling with this question for a couple of days now.
Question: How can I pull multiple strings that match my search criteria between two lines in C#?
Here is my current process:
Read all lines of a file.
text_file = "C:\test.txt"; string[] file_text = File.ReadAllLines(text_file);Loop through each line of the file and search for matches
foreach (string line in file_text) { Regex r1 = new Regex(@"Processor\(s\):\s+.+\n\s+(.+)\nBIOS Version:"); Match match1 = r1.Match(line); if (match1.Success) { string processor = match1.Groups[1].Value; // Just to see if I matched anything System.Windows.MessageBox.Show(processor); } }Here is the example text:
Processor(s): 1 Processor(s) Installed. [01]: Intel64 Family 6 Model 23 Stepping 10 GenuineIntel ~2826 Mhz BIOS Version: Phoenix Technologies LTD 6.00, 7/30/2013
Problem: I used the website "RegExr" and "Regex101" which shows that the processor name should be captured in "Groups[1]" but nothing appears to be captured when I attempt to dump it to a message box.
Any advice would be greatly appreciated!
Thank you!