wiki:RegexIncludeMacro

Version 8 (modified by dfaerch, 8 years ago) (diff)

title

Include and do Regex-replacements

Description

This is a hack upon the Include macro, that adds regular expression replace functionality.

Very usable when you whish to extract data from and/or change data inside an included page.

Arguments:

  • arg 1 : url - Like the Include macro except, local files cannot be included1
  • arg 2 : format. Either "wiki" or "raw", where wiki does WikiFormatting
  • arg 3+: <more to come>
  • arg last:The regular expressions MUST be the last argument

Regular expressions are defined as such:
'&lt;expression&gt;','&lt;replacement&gt;'
You can use several expressions, seperated by semicolon:
'&lt;expression&gt;','&lt;replacement&gt;';'&lt;expression&gt;','&lt;replacement&gt;'

You can also use capture groups. In python (i learned) these are defined as \1,\2 ect. (where in eg. perl its $1,$2)


  1. 1. Well, they can if the file resides in /tmp/trac_include/ and no slashes are used in filename.

Bugs/Feature Requests

Existing bugs and feature requests for RegexIncludeMacro are here.

If you have any issues, create a new ticket.

Download

Download the zipped source from here.

Source

You can check out RegexIncludeMacro from here using Subversion, or browse the source with Trac.

Examples

A simple example. Replace all occurences of the word &#34;windows&#34; with the word &#34;Linux&#34;

[[RegexInclude(http://yourpage.tld,raw,'[Ww]indows','Linux')]]

The next example includes http://www.kernel.org/kdist/finger_banner and wiki-formats the wanted data, and removes the unwanted. Perticulary, i want to only keep the major version information, not patches nor snapshots.

Note how i use 2 regular expression replaces, seperated by ';'. The first expression formats the lines i want to keep, the second deletes the rest.

[[RegexInclude(http://www.kernel.org/kdist/finger_banner,wiki,'The latest ([\w.]+) version [^:]+:\s*([a-z0-9.-]+)',' '''\1''' :: \n  ''\2'' ';'\nThe[ a-zA-Z0-9.:-]+','\n')]]

The result is:

stable
2.6.18

2.4
2.4.33.3
2.2
2.2.26

Known limitations

  • Your expressions or replacement-strings cannot contain ';' (that is: tick-semicolon-tick) since that combination is used for splitting the expressions:
  • Your expressions or replacement-strings cannot contain ',' (that is: tick-comma-tick) since that combination is used for splitting the expression from replacement-string.

I hope these two combinations are so unlikely, that the limitation wont cause any trouble.

Recent Changes

[1357] by dfaerch on 2006-10-09 11:53:17
RegexIncludeMacro:

Added regex match functionallity + match_seperator

[1342] by dfaerch on 2006-10-05 15:38:53
RegexIncludeMacro:

added Control Arguments & wiki-page inclusion

[1338] by dfaerch on 2006-10-04 16:16:19
RegexIncludeMacro:

initial release

Author/Contributors

Author: dfaerch
Contributors: