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
  • PrintPrint
Share this Page URL
Help

Chapter 3. Regular Expressions > Item 31. Use named captures to label matches

Item 31. Use named captures to label matches

Wouldn’t it be grand if you didn’t have to remember all of those numbered variables to get the parts of the string you matched? Consider the annoyances you’ve had to tolerate. For instance, say you write a regular expression to match a couple of names:

$_ = 'Buster and Mimi';
if (/(\S+) and (\S+)/) {
  my ( $first, $second ) = ( $1, $2 );
  ...;
}


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint