Loading...
 
Skip to main content

PluginRegex

Using this plugin as a quick tag is not advised as yet. Repairs on the way.

A line break for Tiki syntax would be very very useful to get the full text processing power out of regex.

  • Mose mentioned a
    wiki line break tag.


regex
Copy to clipboard
<?php // Perform a regular expression on the text surrounded by {REGEX()} {REGEX} tags // Usage the WikiPageName holds the regex find replace commands // for example /^i/i:: $1 is the first letter // where $1 is the value of the first expression // example two: /(it's|its)(your|you're):: Check $1 $2 is correct // {REGEX(search=>WikiPageName)} // line 2 // line 3{REGEX} function wikiplugin_regex_help() { return tra("Takes regex expressions and parses the content between the REGEX tags and replaces the text.").": <br/>{REGEX(regex=>search|replace)}".tra("data")."{REGEX} - ''".tra("one data per line")."''"; } function wikiplugin_regex($data, $params) { global $tikilib; extract ($params); $pageName = (isset($pageName)) ? $pageName : "pageName";//gets a page $info = $tikilib->get_page_info($pageName); $content=$info["data"]; $lines = explode("\n", $content); // separate lines into array no emtpy lines at beginning mid or end foreach($lines as $line){ list($search[],$replace[])=explode("::",$line);// use two colons to separate your find and replace } $data=preg_replace($search,$replace,$data); $data = trim($data); return $data; } ?>

for example
Copy to clipboard
{REGEX (search=>MyPageOfRegexpression)} Its a matter of choice. {REGEX}

Will produce

Did you check to see if you are using its correctly? a matter of choice.

Here is the content of ))MyPageOfRegexpression((

Copy to clipboard
/\./::\. /(its|it's)/i::Did you check to see if you are using $1 correctly? /(\n|^)(a-z)/::$1 Capitalize $2 as it is the beginning of your sentences. /.\n<br>/::. The end of the sentence. / \t+$/::Don't put blank lines at the beginning. /(stuff|things|stupid|whack)/i::Find a better word. $1 is immature. /(accept|except)/i::$1 is often misused. Check your usage. /(there|their|they're)/i::Are you sure you're using $1 correctly? /(collage)|(college)/i::$2 is where you make colleagues and have a $1 experiences


There is lots of room for improvement here but here are some sample strings to get you started.... mind you, they are aimed at relieving the tedium of correcting stupid typographical errors... but the potential is enormous.


Page last modified on Tuesday 03 August 2004 05:23:40 GMT-0000