File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Regex Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regex Problem" Watch "Regex Problem" New topic
Author

Regex Problem

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
My Basic aim is to extract a string FP009Y260KP from the input String. I tried as below. But my code fetches me as FP009Y260KP/X_008_01_17_16_FP009Y260KPwhich is incorrect. How do I fetch FP009Y260KP alone.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36555
    
  16
What you are matching is FP then any number of anything else until you reach KP. It appears to be acting in a "greedy" fashion. Go through the Regular Expression part of the Java Tutorial and look particularly for greedy and reluctant quantifiers, etc.
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Thanks. I could do it through reluctant quantifier. And it works fine now.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36555
    
  16
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex Problem
 
Similar Threads
Input from keyboard
Can someone check my program?
try/catch vs null check
Static Methods Problem
parsing date as a string