Solved

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

Posted on 2012-03-28
5
304 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 43
use lov values 2 61
How  can  i  resolve  HTTP Status 404 -? 8 42
SequenceInputStream example 3 19
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

840 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