Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Greedy Quantifiers

 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I got it and now I'm understanding it. Thanks for the reply.
Thanks Barry for your comments.
Regards,
Jothi Shankar Kumar. S
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic