• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 828
  • Last Modified:

java reg expression string search

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
cfans
Asked:
cfans
  • 4
  • 4
  • 3
1 Solution
 
ZvonkoSystems architectCommented:
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
 
cfansAuthor Commented:
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
 
ZvonkoSystems architectCommented:
Some examples for the COMPLETE string of the message would be good and the statements what parts you expect where.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZvonkoSystems architectCommented:
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
 
cfansAuthor Commented:
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
 
ZvonkoSystems architectCommented:
And why do you not post an example sting?
0
 
CEHJCommented:

>>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
 
CEHJCommented:
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
 
cfansAuthor Commented:
CEHJ.. what if there are more than one within a single line?
0
 
CEHJCommented:
Replace if by while
0
 
CEHJCommented:
:-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now