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. Regular Expressions > Item 34. Avoid greed when parsimony is best

Item 34. Avoid greed when parsimony is best

Greed isn’t about money, at least where regular expressions are concerned. It’s the term used to describe the matching behavior of most regular-expression engines, Perl’s included.

A general rule is that a Perl regular expression will return the “leftmost longest” match it can find, at the first position in a string where it can find a match of any length. Repetition operators like * and + “gobble up” characters in the string until matching more characters causes the match to fail:


  

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