Forums Register Login

HELP w/Scanner question 41 in final test in examlab

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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)
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
@ Costi Ciudatu
well you have given a damn good explanation man thanks for it.........
+Pie Number of slices to send: Send
just google regex...you will get some superb tutorials on it.
+Pie Number of slices to send: Send
thank you champak
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1089 times.
Similar Threads
Scanner class
how the execution happens?
string search
pulling my hair out
arrays
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:01:49.