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.
Suppose there is a topic with a table defining entries in a TWikiForm. I.e. they define select menu items in a form template. They are then formatted like:
Which expands to this: (here limited to all Z* users because TWiki.org has so many)
This searches all topics in the Main web that contain "Name", "Email" and "Country" bullets. Alternatively, do a FormattedSearch with multiple="on" on the Main.TWikiUsers topic.
Solution 2: As Solution 1, but with possibility for multi-selecting usernames
The example of Solution 1 produces the list box. Add a MULTIPLE to the select statement, i.e.:
<select name="topic" size="2" MULTIPLE>
Please note that the Search pattern is unchanged compared to Solution 1. The change is in the HTML form element.
The abovementioned modification is, in effect:
Solution 3: Appropriate for TWiki 4 (Dakar)
When the User information is stored in a UserForm (as is default in Dakar) then this list can be generated as follows:
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
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?
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 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:
Public webs of TWiki.
For private webs, or any other webs you wish to exclude from the display, use "on" for the Exclude web from a web="all" search setting in the relevant web's WebPreferences topic.
Alternative solution
This result can also be accomplished with the %WEBLIST% variable.
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.
Pattern 10: Search all topics that have been moved