The use of REGEX pattern is an easy issue to me.
I have read about it on INTERNET but I got it stiil more blurred.
Justin SmithLevel 41, Greenfield, USA, United States
19 October 2021
This chapter is secretly actually about working with regex. The filereader/filewriter part is basically pretty simple and doesn't really change much from task to task.
Tip. Putting a character inside square brackets avoids the need to look up most escape sequences. i.e. "[!#.]" will match "!", "#", and "."
these tasks were more about RegEx than I/O.
check out this page (choose java on the left and look on the bottom right for RegEx quick references):
https://regex101.com/
On the counting words task use "\\W" to split the string instead of "\\p{Punct}" even though the task says "The file contains words separated by punctuation marks." I kept failing the verification because of this and couldn't figure out why until I looked at the help section.
I replaced all whitespaces with '.' and then \\p{Punct} was also accepted. --
And a little bit more precise description of the task would like this:
- "The file contains words separated by punctuation marks and/or whitespaces",
- the words "world" count only in lower case,
- "worlds", "worldly" : these do not count.
one tip I would like to share with you, always check others solution in the help section after you pass the task, you will see some amazing solution and learn to write the better code.
Happy learning.
GO TO FULL VERSION