Question
The first pattern in
SearchPatternCookbook shows how to extract values from a table. Clearly, this is useful to pull values from a form field values definition.
I'm trying to do that but also to extract the tooltip information too. And, try as I might, I cannot get the tooltip info to show up from a $pattern() ... that third field just seems to want to be ignored and with several tried patterns I get the text of the $pattern rather than any result.
Even if I try to greedily match the whole row, my recollection is I just get the pattern.
I think I was unsuccessful in getting the "option" text to output, as well.
Environment
--
MatthewKoundakjian - 05 Jul 2007
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
Here is a the same search as the example but with the tooltip also outputted:
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="Name: $pattern(^\| *(.*?) *\|.*), tooltip: $pattern(\|[^\|]*\|[^\|]*\| *(.*?) *\|.*)<BR>" }%
About getting the $pattern instead of the matched text: this happens when you use a gready dot (
.*). This is some kind of bug or limitation of $pattern, which is also mentioned in
TWiki.FormattedSearch. It makes writing patterns a bit harder..
--
JosKunnekes - 06 Jul 2007
Jos ... what do you do instead?
--
MatthewKoundakjian - 06 Jul 2007
You can use almost anything instead. Consider this search:
| Name |
Type |
| One |
option |
numbaone |
| Two |
option |
numbatwo |
| Three |
option |
numbathree |
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="Name: $pattern(^\| *(.*) *\|[^\|]*\|.*)<BR />" }%
The result:
Name:
\|[^\|]*\|.)
Name:
\|[^\|]*\|.)
Name:
\|[^\|]*\|.)
It doesn't work, but prints the pattern instead, because it contains a greedy dot:
$pattern(^\| *(.*) *\|[^\|]*\|.*)
Now if we replace
(.*) by
-
(.*?)
-
([^\|]*)
-
([\w\W]*)
- or
(.?.+)
respectively, of which the last two have almost the same meaning, it does work:
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="Name: $pattern(^\| *(.*?) *\|[^\|]*\|.*)<BR />" }%
Name: One
Name: Two
Name: Three
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="Name: $pattern(^\| *([^\|]*) *\|[^\|]*\|.*)<BR />" }%
Name: One
Name: Two
Name: Three
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="Name: $pattern(^\| *([\w\W]*) *\|[^\|]*\|.*)<BR />" }%
Name: One | option
Name: Two | option
Name: Three | option
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="Name: $pattern(^\| *(.?.+) *\|[^\|]*\|.*)<BR />" }%
Name: One | option
Name: Two | option
Name: Three | option
So I guess you can basically use anything as long as you keep
.* out of the regex (except at the end). Even this
((?:.+)?) or this
(.{0,}) does the trick
--
JosKunnekes - 07 Jul 2007
Jos, you rock.... I wasn't trying to get the first field, but a third field ... but your examples were adaptable. I'm going to use:
%SEARCH{ "^\|[^\|]*\| *option *\|" topic="%TOPIC%" type="regex" multiple="on" nosearch="on" nototal="on" format="Name: $pattern(^\|[^\|]*\|[^\|]*\| *(.?.+) *\|.*)<BR />" }%
Name: numbaone
Name: numbatwo
Name: numbathree
--
MatthewKoundakjian - 08 Jul 2007
Here's the final version of what I was after....
%SEARCH{ "^\|[^\|]+\| *option *\|[^\|]+\|" topic="Category" type="regex" multiple="on" nosearch="on" nototal="on" format="---++ [[%SCRIPTURL{"view"}%/%WEB%/Category?category=$pattern(^\| *(.*?) *\|.*)][$pattern(^\| *(.*?) *\|.*)]] %BR%$pattern(^\|[^\|]*\|[^\|]*\| *(.?.+) *\|.*)%BR%" }%
--
MatthewKoundakjian - 08 Jul 2007