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
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply 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: 792
    
    2

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
    
    7

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?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Extract values from a String
 
Similar Threads
how to extract tagged version of java code in build.xml
error in struts program
Hibernate - multiple collection with restrictions mapping problem
Reading dll version in java or any other method.
Object creation