Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELP w/Scanner question 41 in final test in examlab

 
Fritz Guerilus
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Costi Ciudatu
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Costi Ciudatu
well you have given a damn good explanation man thanks for it.........
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just google regex...you will get some superb tutorials on it.
 
Phungsuk Wangdu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you champak
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic