File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extract values from a String

 
Mary Cole
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Check java.util.regex.Pattern and java.util.regex.Matcher classes.
 
Manoj Kumar Jain
Ranch Hand
Posts: 195
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 9497
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic