| Author |
Extract values from a String
|
Mary Cole
Ranch Hand
Joined: Dec 02, 2000
Posts: 362
|
|
Hi,
I have a String which is in the following format.
IS there a way in Java to extract the value after NAME: , VERSION: and CAT: using REGEX?
Thanks in advance
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
|
Yes. Check java.util.regex.Pattern and java.util.regex.Matcher classes.
|
The quieter you are, the more you are able to hear.
|
 |
Manoj Kumar Jain
Ranch Hand
Joined: Aug 22, 2008
Posts: 191
|
|
You can also achieve your goal without using regex. If this is the fixed format for the string just go and look for the end index of the keyword like NAME, VERSION etc. then find out the index of "]" just after this current index and fetch out the value in between the two indexes.
|
Do not wait to strike till the iron is hot; but make it hot by striking....
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4726
|
|
Mary Cole wrote:IS there a way in Java to extract the value after NAME: , VERSION: and CAT: using REGEX?
Yes, but first you think to think about what is the same and what is different about all those searches.
Regex is a pattern matcher, so you need to be looking for patterns, not specific Strings.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
 |
|
|
subject: Extract values from a String
|
|
|