jQuery in Action, 2nd edition
The moose likes Beginning Java and the fly likes greedy quantifier Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "greedy quantifier" Watch "greedy quantifier" New topic
Author

greedy quantifier

Isaac Lee
Greenhorn

Joined: Feb 25, 2005
Posts: 2
I have the following program :


I get the result like this:

0f
1


For the program below:



I get the result :
0f

I don't understand why the results are different. In my understanding, the first program should give the result 0f , the same as the second. why is it different?

Thanks.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

Please check your private messages for an important administrative matter.


[My Blog]
All roads lead to JavaRanch
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

In the first case, the pattern is zero or one letter f. In the second case, the pattern is one or more letter f. It is the zero letter f part of the first pattern that allows the second match.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Isaac Lee
Greenhorn

Joined: Feb 25, 2005
Posts: 2
Thank you. Henry
Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
[Deleted entire post as "hi-jack." Original in our "deleted" forum. CR]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: greedy quantifier
 
Similar Threads
Regular expression not finding string
doubt on group() in Matcher class
regex grouping and OR
Pattern Syntax Exception
When "\'something'" or "\\'something'" will not compile