Reg exp question?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top