aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes HELP w/Scanner question 41 in final test in examlab Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "HELP w/Scanner question 41 in final test in examlab" Watch "HELP w/Scanner question 41 in final test in examlab" New topic
Author

HELP w/Scanner question 41 in final test in examlab

Fritz Guerilus
Ranch Hand

Joined: Jun 20, 2009
Posts: 65
Hi,
Can someone help explain how the answer to this code turned out to be "> Final <"?

I get lost in the section: "("\\s[A-Z]([a-z])*\\s"))"

I understand that \\s is looking for white spaces, and [A-Z] is looking for capital letter between A-Z, but I get lost with the rest of the expression.

My scanner knowledge is weak, and I can't seem to figure the regex section of K&B SCJP6 study guide very well

I'm short on time and I would really, really appreciate a prompt response
-Thanks in advance
-Fritz


SCJP 6.0
Costi Ciudatu
Ranch Hand

Joined: Oct 24, 2006
Posts: 74
The section you got lost in is a regular expression, so it has little to do with the java.util.Scanner itself.
That regexp stands for the following sequence: a 'space': \\s followed by an upper-case letter: [A-Z] followed by 0 or more lower case letters: ([a-z])* and ended with a 'space': \\s. The only matching of this in your String is " Final ".
(\\s stands for more than the <space> character)
Fritz Guerilus
Ranch Hand

Joined: Jun 20, 2009
Posts: 65
Costi Ciudatu wrote:The section you got lost in is a regular expression, so it has little to do with the java.util.Scanner itself.
That regexp stands for the following sequence: a 'space': \\s followed by an upper-case letter: [A-Z] followed by 0 or more lower case letters: ([a-z])* and ended with a 'space': \\s. The only matching of this in your String is " Final ".
(\\s stands for more than the <space> character)


Thank You, Thank You. I was really over complicating it. That was a simple explaination, but to me it just looked difficult.
Thank You again for the quick response
Phungsuk Wangdu
Ranch Hand

Joined: Nov 04, 2009
Posts: 114
@ Costi Ciudatu
well you have given a damn good explanation man thanks for it.........
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
just google regex...you will get some superb tutorials on it.


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Phungsuk Wangdu
Ranch Hand

Joined: Nov 04, 2009
Posts: 114
thank you champak
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP w/Scanner question 41 in final test in examlab