This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 37884
    
  22
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: 37884
    
  22
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex Problem
 
Similar Threads
parsing date as a string
Static Methods Problem
Can someone check my program?
Input from keyboard
try/catch vs null check