Question
I'd like to put a
portion of the search results into a variable and use that variable elsewhere. Better yet, I would like to use the result portion in a view template. Simply put, the following search tells me how many registered users I have:
%SEARCH{ "[N]ame:;Email:;Location:" web="Main" type="regex" nosummary="on" nosearch="on" format="$nop"}%
which results in something like:
"Number of topics: 780"
I am not a regex guru - I was hoping someone could point me to a solution -- using the value in a VIEW template is my ultimate goal.
Thanks
Environment
--
SteveRJones - 27 Feb 2006
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.
If you just want to calculate the total, use a spreadsheet formula to increase a counter on each hit, then read the counter elsewhere.
Example:
%CALC{$SET(total,0)}%
%SEARCH{ "testing" type="regex" nosearch="on" nototal="on" format="$percntCALC{$SETM(total,+1)}$percnt" }%
The total is: %CALC{$GET(total)}%
Output:
The total is: 320
You can do more fancy stuff, such as conditionals based on a
$pattern() in the
FormattedSearch.
--
PeterThoeny - 27 Feb 2006
Ack, I never thought of that! But $pattern and regex's still have me stymied. Peter, I learn by typically testing and watching how code iteratively operates - but using $pattern is typically an all or nothing - it either works or it doesn't and all my attempts seem to not work. Any pointers to some really good tutorials on making regex' work?
Thanks
--
SteveRJones - 28 Feb 2006
It takes some time to get used to regular expressions. TWiki's doc is at
RegularExpression. I learned a lot from the
Perl Camel book
,
ISBN:0-596-00027-8
Check out also:
--
PeterThoeny - 28 Feb 2006
Ok, I just purchased used books from Amazon - Perl book and master Regular Expressions. I'm determined!
Thanks Peter!
--
SteveRJones - 28 Feb 2006

Remembers me to have a look into my copy of
Mastering Regular Expressions
once in a while. Did get this as christmas present two years ago.
--
FranzJosefSilli - 28 Feb 2006