S
stanly.lau
Hi, I wanted to capture 4 columns (date, time, status, message) of data
from the following log sample using regexp but only managed to retrieve
a portion of the message when there are multiple lines using the
following method. I know I'm missing something on my regexp to retrieve
the rest of the message lines. Is there anybody able to help me on
this?
Thanks in advance!
Stanly
Scanner s = new Scanner(new FileInputStream("test.log"));
while(s.hasNextLine()) {
s.findWithinHorizon("\"(.*)\",\"(.*)\",\"(.*)\" (.*)",0);
try {
MatchResult result = s.match();
for (int i=1; i<=result.groupCount(); i++)
System.out.print(result.group(i) + " - ");
} catch(IllegalStateException e) {
e.printStackTrace();
}
if( s.hasNextLine())
s.nextLine();
System.out.println("\n-------");
}
"12/29/2005","11:40:25 AM","SUCCESS" This is the success mesage
"12/29/2005","11:40:25 AM","SUCCESS" This is the success mesage
"12/29/2005","11:40:25 AM","ERROR" Error found:
Exception in thread "main"
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.accept(Unknown Source)
at java.util.regex.Pattern.group0(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
"12/29/2005","11:40:25 AM","ERROR" Error found:
Exception in thread "main"
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.accept(Unknown Source)
at java.util.regex.Pattern.group0(Unknown Source)
"12/29/2005","11:40:25 AM","SUCCESS" This is the success mesage
from the following log sample using regexp but only managed to retrieve
a portion of the message when there are multiple lines using the
following method. I know I'm missing something on my regexp to retrieve
the rest of the message lines. Is there anybody able to help me on
this?
Thanks in advance!
Stanly
Scanner s = new Scanner(new FileInputStream("test.log"));
while(s.hasNextLine()) {
s.findWithinHorizon("\"(.*)\",\"(.*)\",\"(.*)\" (.*)",0);
try {
MatchResult result = s.match();
for (int i=1; i<=result.groupCount(); i++)
System.out.print(result.group(i) + " - ");
} catch(IllegalStateException e) {
e.printStackTrace();
}
if( s.hasNextLine())
s.nextLine();
System.out.println("\n-------");
}
"12/29/2005","11:40:25 AM","SUCCESS" This is the success mesage
"12/29/2005","11:40:25 AM","SUCCESS" This is the success mesage
"12/29/2005","11:40:25 AM","ERROR" Error found:
Exception in thread "main"
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.accept(Unknown Source)
at java.util.regex.Pattern.group0(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
"12/29/2005","11:40:25 AM","ERROR" Error found:
Exception in thread "main"
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.accept(Unknown Source)
at java.util.regex.Pattern.group0(Unknown Source)
"12/29/2005","11:40:25 AM","SUCCESS" This is the success mesage