Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex Problem

 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I could do it through reluctant quantifier. And it works fine now.

 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic