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.
Pattern 3b: listbox with all user names - select multiple names
Problem
Suppose you want to send mail from a form on topic page to a selected list of multipleTWikiUsers
Solution
The example of Pattern 3a 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 Pattern 3a. The change is in the HTML form element.
Test case
The Search pattern 3a with the abovementioned modification is, in effect:
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
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]]
So the total Search query to find a topic's parent topic is:
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.
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 8: Search all topics that have been moved
Problem
How would I go about listing all moved topics ?
Solution
Search for the META:TOPICMOVED meta data. Type this:
Moved topics: %SEARCH{ "%META\:TOPICMOVED" regex="on" format="$topic, " nosearch="on" noheader="on" nosummary="on" }%
to get this (limited to 10 results):
Moved topics: Number of topics: 0