|
Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://wiki.cs.msu.ru/System/SearchPatternCookbook
Дата изменения: Unknown Дата индексирования: Sat Apr 9 23:49:38 2016 Кодировка: koi8-r |
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.
| *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?
<form>
<select>
%SEARCH{
"^\|[^\|]*\| *option *\|"
topic="%TOPIC%"
type="regex"
multiple="on"
nonoise="on"
format="<option>$pattern(^\| *(.*?) *\|.*)</option>"
}%
</select>
</form>
which is, in effect:
| *Country* | | | | Afghanistan | | Aland Islands | | Albania | | Algeria | | American Samoa | | Andorra |You need to skip the header row. Use this search:
<select>
%SEARCH{
"^\|[^\*\|]*\|"
topic="CountryList"
type="regex"
multiple="on"
nonoise="on"
format="<option>$pattern(^\| *(.*?) *\|.*)</option>"
}%
</select>
Which renders as:
| a | b | c | d | e | | Marketing | b | c | d | e| | a | b | c | d | e | | a | marketing | c | d | e | | a | b | c | d | marketing |use this query:
%SEARCH{
"^\|.*?Marketing.*"
type="regex"
topic="%TOPIC%"
multiple="on"
nonoise="on"
format="| $pattern(^\| *(.*?) *|.*)"
}%
Which renders as:
| Marketing | b | c | d | e |
| a | marketing | c | d | e |
| a | b | c | d | marketing |
%SEARCH{
"TopicClassification='%URLPARAM{type}%'"
type="query"
nonoise="on"
sort="topic"
format=" * $topic - <font face='arial,helvetica' size='1'>
_last modified by_ $wikiusername _on_ $date </font> %BR%
<font face='arial,helvetica' size='1'> $formfield(TopicStatus) </font>"
}%
The filtering select dialogue is created as in Pattern 1:
%STARTSIDEBAR%
*Filter:* %BR%
<form name="selectType" action="%SCRIPTURLPATH{"view"}%/%WEB%/" >
<select name="type" size="1" onchange="document.location=this.value;">
%SEARCH{
"^\|[^\|]*\| *option *\|"
topic="TopicClassification"
type="regex"
nonoise="on"
format="<option value='%BASETOPIC%?type=$pattern(^\| *(.*?) *\|.*)'>
$pattern(^\| *(.*?) *\|.*)</option>"
}%
<option value='%BASETOPIC%'>All pages</option>
</select>
</form>
%STOPSIDEBAR%
This will create similar functionality as Foswiki:Extensions.TopicClassificationAddOn
How to get to the parent of the current topic to display on the page?
Use the QUERY macro:
%QUERY{ "parent.name" }%
How to get to the list of all children of the current topic to display on the page?
The parent information is stored in the topic meta data. Do a SEARCH to find all topic parent meta data pointing to the current topic:
Children:
%SEARCH{
"parent.name='%TOPIC%'"
type="query"
nonoise="on"
format="[[$topic]]"
separator=", "
}%
Note: Replace %TOPIC% with %BASETOPIC% if you put this SEARCH into the skin or a sidebar.
See also HierarchicalNavigation for an elaborate example.
How to find and display public webs in a drop down list box.
<form>
<select name="topic">
<option value="%TOPIC%">Select...</option>
%SEARCH{
"%HOMETOPIC%"
scope="topic"
web="all"
topic="%HOMETOPIC%"
format="<option value='$web.$topic'>$web</option>"
separator=" "
}%
</select>
<input type="submit" class="foswikiSubmit" value="Go" />
</form>
Public webs can be found with the %WEBLIST% macro.
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 following search pattern can be employed:
<select name="type">
<option>Select category...</option>
%SEARCH{
" *\s*.*?"
topic="CategoryList"
type="regex"
multiple="on"
casesensitive="on"
nonoise="on"
format="<option>$pattern(.* \*\s*([^\n]*).*)</option>"
}%
</select>
To render the bullet list as a comma-separated list, use the separator parameter:
%SEARCH{
" *\s*.*?"
topic="CategoryList"
type="regex"
multiple="on"
casesensitive="on"
nonoise="on"
separator=","
format="$pattern(.* \*\s*([^\n]*).*)"
}%
How would I go about listing all moved topics ?
Search for the 'moved' meta data. Type this:
Moved topics: %SEARCH{
"moved.from=~'\w+'"
web="all"
type="query"
separator=", "
format="$web.$topic"
nonoise="on"
}%
$pattern() token. Type this:
%SEARCH{
"^---[+][^+][^\r\n]+[\r\n]"
type="regex"
nonoise="on"
header="Headings:"
limit="5"
format=" * [[$topic][$pattern([\r\n\-+!]+([^\r\n]*?)[\r\n].*)]]"
footer="Found $ntopics topics with level-1 headings"
}%
Copyright © by the contributing authors. All material on this site is the property of the contributing authors.