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 32. Use noncapturing parentheses when you...

Item 32. Use noncapturing parentheses when you need only grouping

Parentheses in Perl regular expressions serve two different purposes: grouping and capture. While this is usually convenient, or at least irrelevant, it can get in the way sometimes. For instance, if you want to match the Subject: line of an e-mail, ignoring possible reply prefixes, you might use two sets of parentheses:

my ( $bs, $subject ) = /^subject:\s+(re:\s*)?(.*)/i


  

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