aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Greedy Quantifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Greedy Quantifiers" Watch "Greedy Quantifiers" New topic
Author

Greedy Quantifiers

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

I'm confused on the greedy quantifiers topics. Could anyone please tell me what the following means?

Source : yyxxxyxx
Pattern: .*xx


What will be the result of the above and why? I would be happy if anyone would tell me what these quantifiers are really?

Thanks Beforehand,
Jothi Shankar Kumar. S


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

It's me again with my second doubt on a more or less related topic as above.

What would the following line print?

System.out.println("\" \\");

What would the following line print?

String s = "ab.cde.fg";
String[] tokens = s.split("\\.");


I'd be happy if anyone could explain me this apart from just typing the o/p.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please keep your questions separate. Otherwise things are going to get very messy very quickly.

And: have you coded these up and tested things yourself? What results are you expecting from these expressions? Or do you want someone to do it all for you?
[ September 27, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

Hello there,

I'm not understanding the concept and that is why I posted my question and this one was from the K&B book. I really didnt unerstand this and I think one can just explain it as they are just 2 lines of code. So if anyone could help me...please do.

Note: Barry!
I shall not post multiple questions anymore. I'm sorry!

Regards,
Jothi Shankar Kumar. S
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Regarding your first question, there is an explanation of how it works on page 480 of K & B. What do you not understand about that explanation?
Santhosh Raje
Greenhorn

Joined: Sep 26, 2006
Posts: 9
Hey ,
Just some input on what I know on Greedy Quantifiers is that
The Source:yyxxxyxx and the Pattern:*.xx
Here the Pattern is matched for this particular source.
What happens during matching is the Condition is that From the source match for tokens that end with xx.
So the JVM can interpret as yyxx as one token or yyxxx as another token and last xyxx as another token(Totally:3)
While the actual number of tokens what we expect is 2.

So they kept the name as Greedy Quantifiers
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Santhosh PR:
Hey ,
Just some input on what I know on Greedy Quantifiers is that
The Source:yyxxxyxx and the Pattern:*.xx
Here the Pattern is matched for this particular source.
What happens during matching is the Condition is that From the source match for tokens that end with xx.
So the JVM can interpret as yyxx as one token or yyxxx as another token and last xyxx as another token(Totally:3)
While the actual number of tokens what we expect is 2.


Unfortunately the above is wrong. The result obtained from a greedy match is that given in the K & B book - just one long match.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Oh yes, Hello "Santhosh PR"-

Welcome to JavaRanch.

On your way in you may have missed that we have a JavaRanch Naming Policy for displayed (screen) names. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Since yours "Santhosh PR" does not conform with it, please take a moment to change it, which you can do right here.

Posters with nonconforming displayed names will be locked out of JavaRanch after a few posts using those names.

Thanks
-Barry

(NR) - warning search tag
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

Ok, I got it and now I'm understanding it. Thanks for the reply.
Thanks Barry for your comments.
Regards,
Jothi Shankar Kumar. S
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Greedy Quantifiers