aspose file tools*
The moose likes Java in General and the fly likes Extract values from a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Extract values from a String" Watch "Extract values from a String" New topic
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: 825
    
    5

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: 8008
    
  22

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?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extract values from a String