The Search function in TWiki is very powerful. Especially searches using a RegularExpression play an important part of tapping TWiki's full potential. Unfortunately RegularExpressions can be incredibly obscure to the uninitiated.
Most people not familiar (enough) with Regular Expressions mostly cut and paste (and maybe tweak) from existing examples. This page intends to collect lots of examples together.
Changed:
< <
> >
Added:
> >
<-- ========================== -->
Pattern 1: Extract values from a table
Problem definition
Line: 27 to 32
<form>
<select>
Changed:
< <
> >
Line: 35 to 40
which is, in effect:
Changed:
< <
> >
Deleted:
< <
Added:
> >
<-- ========================== -->
Pattern 2: List generated from form classification
META:FORM.*[U]serForm will search for all topics with a UserForm attached - change this if you have a different form where userdata is stored. Please note that this search does not actually extract anything from the form - it just uses it to identify the appropriate pages
excludetopic="Test*, TWiki*" allows to skip all topics starting with Test and TWiki, such as TestUser or TWikiAdmin. Use this if you have any special users who you do not want appearing in this list
Added:
> >
<-- ========================== -->
Pattern 4: Extract the parent of a given topic
Problem
How to get to the parent of the current topic to display on the page?
Changed:
< <
Solution
> >
Solution 1: Using META
Since TWiki 4.0 you can now use the META variable:
%META{ "parent" dontrecurse="on" }%
Solution 2: Using SpreadSheetPlugin
You might think that the following Search would do the trick:
However, the [[$parent][parent_link]] link fails if the topic has no parent set ($parent will be empty). You can use some SpreadSheetPlugin magic to conditionally link to the parent or to WebHome: [[$percntCALC{$IF($EXACT($parent,), %HOMETOPIC%, $parent)}$percnt][parent_link]]
> >
However, the $parent link fails if the topic has no parent set ($parent will be empty). You can use some TWiki:Plugins/SpreadSheetPlugin magic to conditionally link to the parent or to WebHome:
Note: Replace %TOPIC% with %BASETOPIC% if you put this SEARCH into the skin or a sidebar.
<-- ========================== -->
Pattern 6: Search and display the home topics of public webs in a list
Problem
Line: 218 to 280
Changed:
< <
Pattern 6: Extract a value from a bullet list
> >
<-- ========================== -->
Pattern 7: Create a select box with values from a bullet list
Problem
We have a topic with a bullet list with category names. In another topic we want to offer these values in a select box dropdown.
For example, CategoryList has:
The td..td matches td<>td; a simple search on "[O]peratingSystem.*[O]sWin" could find a hit in the topic text by coincidence.
A simple %SEARCH{ "[O]peratingSystem.*value\=.*[O]sWin" ...}% search is sufficient if you do not have topics in the old format.
Changed:
< <
Pattern 8: Search all topics that have been moved
> >
<-- ========================== -->
Pattern 10: Search all topics that have been moved
Problem
Added:
> >
How would I go about listing all moved topics ?
Solution
Line: 286 to 393
How would I go about listing all moved topics ?
Solution
Added:
> >
Search for the META:TOPICMOVED meta data. Type this: