• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HELP w/Scanner question 41 in final test in examlab

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Costi Ciudatu
well you have given a damn good explanation man thanks for it.........
 
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you champak
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic