aspose file tools*
The moose likes Beginning Java and the fly likes Regex Doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regex Doubt?" Watch "Regex Doubt?" New topic
Author

Regex Doubt?

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
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 ]
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

Well this works perfectly fine for me.

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
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

Joined: Jan 13, 2008
Posts: 242
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

Joined: May 18, 2007
Posts: 341

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 ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18847
    
  40



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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

Very true Henry. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex Doubt?