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 The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Extract values from a String" Watch "Extract values from a String" New topic

Extract values from a String

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362

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

Joined: Jun 19, 2010
Posts: 825

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: 193

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

Joined: Mar 17, 2011
Posts: 8626

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.


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Have you tried LearnNowOnline?
subject: Extract values from a String