• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regex Doubt?

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a String as below:


I want to capture just FP009Y260KP from the above string. I tried with regex But it says no match found.
[ April 03, 2008: Message edited by: Gopu Akraju ]
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well this works perfectly fine for me.

 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried as below:



It is just printing as below:
java.util.regex.Matcher[pattern=FP.*KP region=0,170 lastmatch=]

What does it mean? How to print FP009Y260KP alone from the test string?
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anand. Both of us should have posted almost the same time. I tried as you mentioned.
System.out.println(matcher.find());
It is just printing trueBut I want to print the string FP009Y260KPThanks again.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this.



I suggest that you should read some good regex tutorials. That will help you enrich your knowledge. Do some googling. That should do.

Also, get the differnce between the methods like matcher.find() , matcher.lookingAt() and matcher.matches(). These subtle differences are really important.
[ April 03, 2008: Message edited by: Anubhav Anand ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Just pointing out the obvious... isn't calling loc_matcher.group() much much easier than calling subtring() with the start() and end() of the match?

Henry
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very true Henry. Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic