RegexParserFunctions Extension

From Jimbojw.com

Revision as of 06:55, 12 May 2007; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

The RegexParserFunctions Extension is a MediaWiki extension that adds a parser function for performing regular expression replacements on text.

It is released under The MIT License.

Compatibility

This extension requires:

  • MediaWiki 1.6.x, 1.9.x, 1.10.x or higher
  • PHP 4.x, 5.x or higer

Installation

  1. Download RegexParserFunctions, and be sure to rename the downloaded file to RegexParserFunctions.php.
  2. Drop the downloaded script in $IP/extensions
    Note: $IP is your MediaWiki install dir.
  3. Enable the extension by adding this line to your LocalSettings.php:
    require_once('extensions/RegexParserFunctions.php');

Usage

Once installed, editors of your wiki can evaluate regular expressions in one of two ways: simple match, and replacement.

Match

In match mode, #regex expects two arguments: a subject and a pattern. The output of the function is either the exact text of the match, or nothing if no match could be made.

For example, this:
{{#regex:abcdefg|/c.*f/}}
Would return this:
cdef

Replacement

In replacement mode, #regex expects three arguments: a subject, a pattern to match and a replacement expression. The output of the function is the result of replacing all matching strings with the replacement expression.

For example, this:
{{#regex:abcdefg|/c.*f/|X}}
Would return this:
abXg

Or, say you're trying to grab the last portion of a Title which is using a '/' to delimit subpages. For that, you could use:

{{#regex:{{PAGENAME}}|%^.*/(.*)$%|$1}}

Comments

Got something to say?

Leave a comment
Sorry, comments are disabled.

or, read what others have said ...