The Search function is very powerful. Searches using a RegularExpression play an important part of tapping Foswiki'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.
Suppose there is a topic with a table defining entries in a data form. I.e. they define select menu items in a form definition. They are then formatted like:
Public webs can be found with the %WEBLIST% macro.
Pattern 6: Create a select box with values from a bullet list
Problem
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:
Error in tempfile() using /home/www/foswiki/working/tmp/XXXXXXXXXX: Could not create temp file /home/www/foswiki/working/tmp/9BGNRvw3BS: No space left on device at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506 at /usr/share/perl5/File/Temp.pm line 1381 File::Temp::tempfile('File::Temp', 'STDERR.4842.XXXXXXXXXX', 'DIR', '/home/www/foswiki/working/tmp', 'UNLINK', 0) called at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506 Foswiki::Sandbox::sysCommand('Foswiki::Sandbox', '/bin/grep -E -l -H -- %TOKEN|U% %FILES|F%', 'TOKEN', '^%META:TOPICMOVED{.*\bfrom=\".*\w+.*\"', 'FILES', 'ARRAY(0xa94ba38)') called at /home/www/foswiki/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 109 Foswiki::Store::SearchAlgorithms::Forking::search('^%META:TOPICMOVED{.*\bfrom=\".*\w+.*\"', 'Main', 'Foswiki::Iterator::FilterIterator=HASH(0xa9b7eb0)', 'Foswiki=HASH(0x8e23088)', 'HASH(0xa9a7f30)') called at /home/www/foswiki/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 267 Foswiki::Store::SearchAlgorithms::Forking::_webQuery('Foswiki::Search::Node=HASH(0xa9b97c8)', 'Main', 'Foswiki::Iterator::FilterIterator=HASH(0xa9b7eb0)', 'Foswiki=HASH(0x8e23088)', 'HASH(0xa9a7f30)') called at /home/www/foswiki/lib/Foswiki/Store/SearchAlgorithms/Forking.pm line 182 Foswiki::Store::SearchAlgorithms::Forking::query('Foswiki::Search::Node=HASH(0xa9b97c8)', 'Foswiki::Iterator::FilterIterator=HASH(0xa9b7eb0)', 'Foswiki=HASH(0x8e23088)', 'HASH(0xa9a7f30)') called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 518 Foswiki::Store::VC::Store::query('Foswiki::Store::RcsWrap=HASH(0x8e59e08)', 'Foswiki::Search::Node=HASH(0xa9b97c8)', 'Foswiki::Iterator::FilterIterator=HASH(0xa9b7eb0)', 'Foswiki=HASH(0x8e23088)', 'HASH(0xa9a7f30)') called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 470 Foswiki::Store::VC::Store::searchInWebMetaData('Foswiki::Store::RcsWrap=HASH(0x8e59e08)', 'Foswiki::Search::Node=HASH(0xa9b97c8)', 'Main', 'Foswiki::Iterator::FilterIterator=HASH(0xa9b7eb0)', 'Foswiki=HASH(0x8e23088)', 'HASH(0xa9a7f30)') called at /home/www/foswiki/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm line 192 Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery('Foswiki::Query::Node=HASH(0xa9ca3d8)', 'Main', undef, 'Foswiki=HASH(0x8e23088)', 'HASH(0xa8f9508)') called at /home/www/foswiki/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm line 78 Foswiki::Store::QueryAlgorithms::BruteForce::query('Foswiki::Query::Node=HASH(0xa9ca3d8)', undef, 'Foswiki=HASH(0x8e23088)', 'HASH(0xa8f9508)') called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 518 Foswiki::Store::VC::Store::query('Foswiki::Store::RcsWrap=HASH(0x8e59e08)', 'Foswiki::Query::Node=HASH(0xa9ca3d8)', undef, 'Foswiki=HASH(0x8e23088)', 'HASH(0xa8f9508)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 839 Foswiki::Meta::query('Foswiki::Query::Node=HASH(0xa9ca3d8)', undef, 'HASH(0xa8f9508)') called at /home/www/foswiki/lib/Foswiki/Search.pm line 352 Foswiki::Search::searchWeb('Foswiki::Search=HASH(0xa8b0620)', 'search', 'moved.from=~\'\w+\'', 'basetopic', 'SearchPatternCookbook', '_RAW', '\x{a} "moved.from=~\'\w+\'"\x{a} web="all"\x{a} type="query"\x{a} ...', 'web', 'all', ...) called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 32 Foswiki::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379 eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371 Error::subs::try('CODE(0x98ee5c8)', 'HASH(0xa9b7950)') called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 41 Foswiki::SEARCH('Foswiki=HASH(0x8e23088)', 'Foswiki::Attrs=HASH(0xa96a480)', 'Foswiki::Meta=HASH(0x98a9918)') called at /home/www/foswiki/lib/Foswiki.pm line 3145 Foswiki::_expandMacroOnTopicRendering('Foswiki=HASH(0x8e23088)', 'SEARCH', '\x{a} "moved.from=~\'\w+\'"\x{a} web="all"\x{a} type="query"\x{a} ...', 'Foswiki::Meta=HASH(0x98a9918)') called at /home/www/foswiki/lib/Foswiki.pm line 3021 Foswiki::_processMacros('Foswiki=HASH(0x8e23088)', '---+!! Search Pattern Cookbook\x{a}\x{a}The Search function is very p...', 'CODE(0x8dcb930)', 'Foswiki::Meta=HASH(0x98a9918)', 16) called at /home/www/foswiki/lib/Foswiki.pm line 2818 Foswiki::innerExpandMacros('Foswiki=HASH(0x8e23088)', 'SCALAR(0x8dcc3b0)', 'Foswiki::Meta=HASH(0x98a9918)') called at /home/www/foswiki/lib/Foswiki.pm line 3327 Foswiki::expandMacros('Foswiki=HASH(0x8e23088)', '---+!! Search Pattern Cookbook\x{a}\x{a}The Search function is very p...', 'Foswiki::Meta=HASH(0x98a9918)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 3103 Foswiki::Meta::expandMacros('Foswiki::Meta=HASH(0x98a9918)', '---+!! Search Pattern Cookbook\x{a}\x{a}The Search function is very p...') called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 412 Foswiki::UI::View::_prepare('---+!! Search Pattern Cookbook\x{a}\x{a}The Search function is very p...', 'Foswiki::Meta=HASH(0x98a9918)', 0) called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 392 Foswiki::UI::View::view('Foswiki=HASH(0x8e23088)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 316 Foswiki::UI::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379 eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371 Error::subs::try('CODE(0x8855958)', 'HASH(0x8e22dc8)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 435 Foswiki::UI::_execute('Foswiki::Request=HASH(0x8e0ff00)', 'CODE(0x8debca0)', 'view', 1) called at /home/www/foswiki/lib/Foswiki/UI.pm line 274 Foswiki::UI::handleRequest('Foswiki::Request=HASH(0x8e0ff00)') called at /home/www/foswiki/lib/Foswiki/Engine/CGI.pm line 41 Foswiki::Engine::CGI::run('Foswiki::Engine::CGI=HASH(0x8a71ef0)') called
Pattern 8: Extract level-1 headings
How do I go about extracting the first occurance of a level-1 heading?