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

Lookaround and Formatting

Lookaround and Formatting

With lookbehind and lookahead you can match text when it is preceded or followed by certain text. This is limited to text only: you can say, “Find an f followed by a closing parenthesis” (using the expression f(?=\))), but you can’t create an expression that says, “Find an italic f followed by a roman closing parenthesis.” In other words, any formatting that you set in Find Format applies to the whole GREP expression.

However, with some GREP trickery it is possible to match text depending on the presence of formatting. It is easy to convert formatting codes to text tags (HTML-like tags, for instance). With such text tags you can then use lookaround to find roman text only when it is preceded or followed by a tag that represents italic text (or any other formatting, but we’ll use italic here for illustration). When you’re done, you convert from tags back to formatted text.


  

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


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