I am trying to parse a log file using regular expressions
and I ran into a challenge. The section
of the log file has a distinct beginning and a distinct end, but the number of
lines in between might vary.
Is there a way I can use regular expressions to pull the beginning of the section, the end of the section and everything in between regardless of the number of lines and or characters?
type undefined is not a vector: (file 'k3/_laserguided.gsc',
line 120)
playfx(level.fx_guided_exp,trace["position"]);
//,trace["normal"]); // SOMETIMES IT PLAYS WRONG
*
Error: started from:
(file 'k3/_laserguided.gsc', line 91)
wait 0.05;
*
Error: ************************************
Any help would be appreciated.
Fernando SotoPosted Jun 11, 2008, 3:11 PM
BrettPosted Jun 9, 2008, 2:41 PM
Much appreciated.
Fernando SotoPosted Jun 9, 2008, 12:20 AM
Hi Brett;
System.Text.RegularExpressions;This sample code should show you how to accomplish what you need.
using
// Read the log file into a local variable
String inputData = new StreamReader("TestData.log").ReadToEnd();
// Regex pattern to look for the script runtime error case insensitive
String pattern = @"(?is)\*{7}\sscript runtime error\s\*{7}.*?Error:\s\*{1,}";
// Locate the text
MatchCollection mc = Regex.Matches(inputData, pattern)
// Display all the matches
foreach (Match m in mc)
{
MessageBox.Show(m.Value);
}
Fernando