Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 3. The simple Groovy datatypes > Working with regular expressions

3.5. Working with regular expressions

Once a programmer had a problem. He thought he could solve it with a regular expression. Now he had two problems.

—from a fortune cookie

Suppose you had to prepare a table of contents for this book. You would need to collect all headings like “3.5 Working with regular expressions”—paragraphs that start with a number or with a number, a dot, and another number. The rest of the paragraph would be the heading. This would be cumbersome to code naïvely: iterate over each character; check whether it is a line start; if so, check whether it is a digit; if so, check whether a dot and a digit follow. Puh—lots of rope, and we haven’t even covered numbers that have more than one digit.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial