Solved

Java: regular expression to filter times in order, how to?

Posted on 2012-03-28
5
302 Views
Last Modified: 2012-03-28
Hello Experts,

The regular expression below is not working for me... I want to filter times and order them...

any thoughts?

thx for your help...

regards,

public class RegularExpression {

	public static void main(String[] args) {
		// log source
		String source = "12:22:22.926_I_I_00 [07:48] function will be continued(0,832569404) \n" +
				"12:22:22.726_I_I_00a [09:04] <<<<<<<<<<<<suspend interpretator(JUMPING), timers:0000 \n" +
				"12:22:22.827_I_I_0 [07:49] function is continued(0,832569404) \n" +
				"12:22:22.828_I_I_00a101c1a3bb4073 [09:06] >>>>>>>>>>>>start interpretator \n " +
				"12:22:22.829 Int 22000  \n" +
				"12:22:22.830_I_I_00a1 [07:38] HERE IS XDATA \n" +
				" 12:22:22.831_I_I_0 [09:04] <<<<<<<<<<<<suspend interpretator(XDATA_EX), timers:00010 \n" +
				" 12:22:22.841_T_I_0000000000000000 [14:0c]  (this dn=Preroute) \n" +
				" 12:22:22.841_I_I_0000000000000000 [01:01] call (2984793-036846a0) for Resources created (del 490) \n" +
				" 12:22:22.931_I_I_0 [09:04] <<<<<<<<<<<<suspend interpretator(XDATA_EX), timers:00010 \n" +
				" 12:22:23.141_T_I_0000000000000000 [14:0c]  (this dn=Preroute) \n" +
				" 12:22:23.841_I_I_0000000000000000 [01:01] call (2984793-036846a0) for Resources created (del 490) \n" +
				"";

//		Vector<String> times = new Vector<String>();
		Pattern timePattern = Pattern.compile("[\\dd]*(\\p{Punct})*[\\dd]*(\\p{Punct})*[\\dd]*(\\p{Punct})*[\\ddd]");
		Matcher timeMatcher = timePattern.matcher(source);
		while (timeMatcher.find()) {
			System.out.println(timeMatcher.group());
//			times.add(m.group());
		}
		


	}// END OF MAIN

}// END OF CLASS

Open in new window

0
Comment
Question by:epifanio67
5 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 250 total points
ID: 37779068
Try this:
Pattern timePattern = Pattern.compile("\\d+:\\d+:\\d+\\.*\\d+");
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37779082
But here you have each line starting with time.
You don't need regex for that make it
ByteaArrayInputStream(source.getBytes())
and then read lnes, trim() them and then so substring (0, 12) and parse it to time
using SimpleDateFormat

What do you want as the output ?
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 250 total points
ID: 37779106
I think this should be more accurate, if you still want regex:

Pattern.compile("\\d{2}:\\d{2}:\\d{2}\\.\\d{3}");
0
 

Author Closing Comment

by:epifanio67
ID: 37779147
thank you experts... both regular expressions work...
for_yan, I am also going to try ByteaArrayInputStream(source.getBytes())....

thx a million...

regards
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37779169
for_yan, I am also going to try ByteaArrayInputStream(source.getBytes())....

Don't bother - use a Scanner ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now