# Search Pattern Cookbook
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.
## Pattern 1: Extract values from a table
### Problem definition
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:
| *Name* | *Type* | *Tooltip message* |
| option1 | option | |
| option2 | option | |
| option3 | option | |
How to extract the 'name' values, i.e. 'option1', 'option2' and 'option3' and put them in a HTML form select input?
### Solution
The following search pattern can be employed:
which is, in effect:
## Pattern 2: List generated from form classification
### Problem
Imagine a TWiki form-based topic classification, i.e. every page has a form with several fields. How to:
1. create a search to display all topics where one form field is set to a certain value
2. create a search to filter the list above based on the values of a second form field
### Test case
In practice: %BR% Image a TWiki form with two fields:
- TopicClassification = One, Two or Three
- TopicStatus = Test or Final
We will:
1. List all topics where the TopicClassification field is set to 'Two'
2. Enable the user to filter this list based on the values of TopicStatus
### Solution
%SEARCH{"[T]opicClassification.*value\=.*Two;[T]opicStatus.*value\=.*%URLPARAM{type}%"
type="regex" casesensitive="on" nosearch="on"
format=" * $topic -
_last modified by_ $wikiusername _on_ $date %BR%
$formfield(TopicStatus) "
sort="topic"}%
The filtering select dialogue is created as in Pattern 1:
%STARTSIDEBAR%
*Filter:* %BR%
%STOPSIDEBAR%
This will create similar functionality as TWiki:Plugins.TopicClassificationAddOn
## Pattern 3: Creating lists of TWiki usernames
### Problem
How to populate a list box with all usernames of registered TWiki users
### Solution 1: Appropriate for Sep 2004 TWiki (Cairo)
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 %SYSTEMWEB%.FormattedSearch with `multiple="on"` on the [[%USERSWEB%.TWikiUsers|USERSWEB/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.: