Solved

java reg expression string search

Posted on 2007-11-17
11
798 Views
Last Modified: 2008-02-01
This is most likely a simple question, but I don't have much experience with regexp's.  

I have a log file which my java program just read in as a string and I'd like to find all occurences of where it says "Error 00-E1122"  where 00-E1122 would obviously change.  So what I need is to get all of the error code values (but just the error value, not including the word Error), ideally have it in a vector of strings.
0
Comment
Question by:cfans
  • 4
  • 4
  • 3
11 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 20304927
Only the numbers?
Can we see some longer text and show you how to get all the rest too?
Also state the message code format. Is the error code format always: 99-E9999


0
 

Author Comment

by:cfans
ID: 20304960
I apologize, this may help... the error code format is always found as: {Error 123ABC} format.  
So you can always be certian that it will be {Error someNumLetterDashSequence} and it will be in the brackets.  All I need is the Number/Letter/Dash sequence.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 20305015
Some examples for the COMPLETE string of the message would be good and the statements what parts you expect where.

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 20305022
Or can we say: all characters following the word "Error" and one or more blanks is the error number. The error number ends when all alpha, digit and dash chars are eaten or char not from the set of error number chars is found, right?

 
0
 

Author Comment

by:cfans
ID: 20305033
Zvonoko, you can say all characters following  "{Error" with 1 or more blank spaces and the error sequence (which is alpha, digit and dash) then ending in "}"
0
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.

 
LVL 63

Expert Comment

by:Zvonko
ID: 20305082
And why do you not post an example sting?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20305097

>>I have a log file which my java program just read in as a string

Sound somewhat inefficient. You should read line by line. What happens when it gets large?


String error = line.replaceAll("\\{Error ([^}]+)", "$1");

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 150 total points
ID: 20305130
Sorry - i must be tiring ;-)


Pattern p = Pattern.compile("\\{Error ([^}]+)");

Matcher m = p.matcher(line);

if (m.find()) System.out.println(m.group(1));

Open in new window

0
 

Author Comment

by:cfans
ID: 20305190
CEHJ.. what if there are more than one within a single line?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20305216
Replace if by while
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20305312
:-)
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

Title # Comments Views Activity
compre toata in where clue oracle 4 55
servlet doXXX methods 3 33
Allow space in this pattern 2 46
Oracle SQL syntax check  without executing 6 29
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

929 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

14 Experts available now in Live!

Get 1:1 Help Now