|
Cookbook /
GrepSummary: Use regular expressions to control what to include from a page
Version: 2010-06-17
Prerequisites: PmWiki 2.2.x
Status: beta
Maintainer: Eemeli Aro
Discussion: Grep-Talk
Description
For example, given a page with a list of news items:
The following directive would allow you to highlight the items with future dates:
To installinclude_once("$FarmD/cookbook/grep.php");
Using the (:grep:) directiveAt its most basic, (:grep Group.Page#section pat=pattern repl=replacement:)
subject may also refer to a section on the current page with (:grep #section ...:). This may be useful for formatting data from the page itself that is hidden using (:if false:). If left empty, the subject will default to the current page, in which case match=1 will also be set to prevent recursion (see below).
pat=pattern should be a valid PHP regexp pattern without delimiters or modifiers, while repl=replacement should be the text with which to replace each found match.
As the example above shows, any (:directives:) in the pattern or replacement will work, if curly brackets are substituted for normal ones: {:directive:}. This is required to correct the order of operations when turning markup into HTML.
All other parameters are optional: (:grep ... mod=abc match=1 limit=123:)
NotesI wrote this recipe today for the exact purpose mentioned in the example: to highlight future event dates in a list of news items. It might have been easier to write some custom code for it, but this way the code is more robust and someone else might find it useful one day. Release notes
See also
ContributorsCommentsSee discussion at Grep-Talk User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |