?
Solved

Java: how to get the line number of the pattern matched?

Posted on 2012-04-12
3
Medium Priority
?
243 Views
Last Modified: 2012-04-12
Hello Experts,

is there a way to get the line number where the pattern was matched?

	public static void main(String[] args) {

		String source = "12:22:22.826 message QueueRoute to 5554443322 \n"
				+ "	response callerAttributes id:5554443322 \n"
				+ "	confirmation callDelivered to agent 675 \n"
				+ "12:22:22.926 message AddRoute to queue 65 \n"
				+ "12:22:23.126 message CancelRoute to queue 45 \n"
				+ "12:22:24.026 message QueueRoute to 3332227766 \n"
				+ "	response callerAttributes id:5558883322 \n"
				+ "	confirmation callDelivered to agent 675 \n" +
				"";
		Pattern p = Pattern.compile("(\\d{2}:\\d{2}:\\d{2}\\.\\d{3}).*(Queue\\w+).*(\\s\\d{10}\\s)"); 
		Matcher m = p.matcher(source);
		while (m.find()) {
			// test
			System.out.println("Time: " + m.group(1));
			System.out.println("call: " + m.group(2) + m.group(3));

		}

	}// end of main

Open in new window


in other words, groups 1, 2, and 3 were found @ line 1 and 6...

see what I mean? any ideas how to do this?

in advance, thank you for any help provided...

regards,
0
Comment
Question by:epifanio67
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 2000 total points
ID: 37840169
Would it be an acceptable solution for you to split the source into lines and then use a for loop to check each line separately? Then you could use the parameter of the for loop as your line counter.
0
 

Author Comment

by:epifanio67
ID: 37840437
let me try that... thx for the suggestion..
0
 

Author Closing Comment

by:epifanio67
ID: 37840597
thank you expert...
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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

765 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