Tags:
create new tag
view all tags

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

TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Irix 6.5.28
Web server: Apache 2.2.4
Perl version: 5.8.x
Client OS: Win xp Pro
Web Browser: Firefox 2.x
Categories: Search

-- MatthewKoundakjian - 05 Jul 2007

Answer

ALERT! 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 smile

-- 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

Change status to:
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2007-07-08 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.