It's better when it's simple

User Tools

Site Tools


This is an old revision of the document!

regExReplacer Plugin

Compatible with DokuWiki

Rincewind, maybe more

plugin Replaces text by regular expressions.

Last updated on

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to replace

Tagged with macro, plugin, regex, replace

The Code was adapted from replace.

This Plugin creates a syntax-plugin for each row in your config-file.


  1. Install the plugin using the Plugin Manager and the download URL above, which points to latest version of the plugin. Refer to Plugins on how to install plugins manually.
  2. create the config file in the default conf-path

Configuring the Plugin

The Plugin uses the config-file to create syntax_plugins dynamically. The File consists of three columns:

  1. parserPattern
  2. preg_replace search-string
    :!: followed by a tab
  3. preg_replace replacement-string

example config

# inhaltsverzeichnisse
\@toc\:[^\r\n!]*[!|\r?\n]	\@toc\:([^\r\n!]*)!?	{{topic>${1}}}
# tagcloud
\@cloud[^\r\n]*[\r\n?|\n]	\@cloud([^\r\n]*)	~~TAGCLOUD${1}~~
# no-cache-feature
\@nocache[\r\n?|\n]	\@nocache	~~NOCACHE~~
# set tags
\@tags\:[^\r\n]*[\r\n?|\n]	\@tags\:([^\r\n]*)	{{tag>${1}}}
# include template
\@tpl\:[^\r\n]*[\r\n?|\n] \@tpl\:([^\r\n]*)	{{template>${1}}}@info: Eingebettet aus //[[${1}]]//*
# newpage-helper
\@newpage[\r\n?|\n]	    \@newpage	{{NEWPAGE>}}
\@newpage\:[^\r\n]*[\r\n?|\n]	\@newpage\:([^\r\n]*)	{{NEWPAGE>${1}}}
# workflow easing
\@fixme\:[^\r\n]*[\r\n?|\n]	\@fixme\:([^\r\n]*)	<wrap>FIXME ${1}{{tag>todo fixme}}</wrap>
# simple info-frame
\@info\:[^\r\n]*[\r\n?|\n]	\@info\:([^\r\n]*)	<wrap info>${1}</wrap>


 * Plugin modMLU: regular expressions to generate a standarized wiki-syntax.
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
class Syntax_Plugin_modMLU extends DokuWiki_Syntax_Plugin {
    public static $subs=0;
    protected static $modMLUconf;
    public static $classDir;
    protected $realClassName = 'wiki mods @ mlu';
    function getInfo() {
        return array(
            'author' => 'Robert Jäckel',
            'email'  => '',
            'date'   => '2012-01-12',
            'name'   =>  $this->realClassName,
            'desc'   => 'Anpassungen des Wikis an der MLU Halle-Wittenberg',
            'url'    => '',
    function getType() { return 'substition'; }
    function getAllowedTypes() { return array('container','substition','protected','disabled','formatting','paragraphs'); }
    function render($mode, &$renderer, $data) { return true; }
    function getSort() { return 999; }
    function generateReplaceClass($setup/*=array($pattern,$search,$replace)*/) {
        $dir = self::$classDir.'modMLU_'.($idx=static::$subs++);
	$file = $dir.'\\syntax.php';
	$fHandle = fopen($file,'w+');
	$generateStr = "<?php \r\n";
	$generateStr .="// file: $file\r\n\r\n";
	$generateStr .="// this file was generated automatically by modMLU-Syntax-Plugin\r\n\r\n";
	$generateStr .='if(!defined(\'DOKU_INC\')) define(\'DOKU_INC\',realpath(dirname(__FILE__).\'/../../\').\'/\');if(!defined(\'DOKU_PLUGIN\')) define(\'DOKU_PLUGIN\',DOKU_INC.\'lib/plugins/\');';
	$generateStr .='require_once(\''.__FILE__."');\r\n\r\n";
	$generateStr .= 'class Syntax_Plugin_modMLU_'.$idx.' extends '.get_class($this)."{\r\n";
	foreach($setup as $k=>$v) $generateStr.='protected $'.$k.' = \''.str_replace('\'','\\\'',$v)."';\r\n";
	$generateStr .= 'protected $subIDX='.$idx.";\r\n}\r\n\r\n";
	return $idx;
        // generate subclass
    function Syntax_Plugin_modMLU() {
        //read cfg-file and create subclasses
	if(isset(self::$modMLUconf)) return true;
	self::$classDir = dirname(__FILE__).'\\..\\';
	$cfg = self::$modMLUconf = confToHash(DOKU_CONF . 'replaceMLU.conf');
	$requires = '';
	foreach($cfg as $pMatch=>$sAction) {
            $aAction = explode("\t",$sAction,2);
    function connectTo($mode) {
	if(!$this->pattern) return;
	$this->Lexer->addSpecialPattern($this->pattern,$mode, 'plugin_modMLU_'.$this->subIDX);
        //check for search string else return
    function handle($match, $state, $pos, &$handler) {
	if ($this->nesting) {
	    $handler->_addCall('cdata', array($match), $pos);
        else {
            $this->nesting = true;
            $nestedWriter = & new Doku_Handler_Nest($handler->CallWriter);
            $handler->CallWriter = & $nestedWriter;
	    /* add magic here */
	    $this->Lexer->parse(preg_replace('/'.$this->search.'/',$this->replace,$match)." \\\\ ");
            $handler->CallWriter = & $nestedWriter->CallWriter;
            $handler->calls[count($handler->calls) - 1][2] = $pos;
            $this->nesting = false;
        return false;


  • How can I use this plugin? The download link is somewhat yield, so cannot install it.
plugin/regexreplacer.1329591649.txt.gz · Last modified: 2012-02-18 20:00 by