Exercises
-
(Patterns, easy) Do a web search to find all the pieces that comprise a URL in its full generality. State what these pieces are. Write a pattern-matching program that checks URLs for validity (such as no embedded spaces). Show the output of your program when run on both good and bad URLs.
-
(Patterns, medium) An email message consists of an arbitrary number of headers, then a blank line, then the body of the text. The headers all have a label followed by a colon, a space, and some optional text all on one line. The "From:" and "To:" headers are required, and come first in that order. The pattern would begin something like this:
Pattern email = Pattern.compile( "^From: .*$" // "From" line + "^To: .*$" // "To" line ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access