This is, perhaps, the most frequently misunderstood concept in TiddlyWiki:
*** Macros are NOT functions ***
They do not "evaluate their contents and return the results". Rather, they just perform TWO actions:
1) replace occurrences of $param$ with corresponding values passed as macro parameters
2) replace occurrences of $(variable)$ with corresponding values of variables define outside the macro
After doing these replacements, the macro's literal contents are inserted in place of the macro call itself.
It is then up to the calling context to do any rendering (aka, "wikification") of the results.
Thus, your second filter becomes:
[search:text:regexp<$macrocall $name="validateregexp" regexp={{!!add.filter}}/>]
and filter operators do NOT process widgets. Thus, the regexp filter operator sees it's parameter
as a reference to a variable named "$macrocall". In addition, variable references inside filters do
not allow use of arguments, so the rest of the $macrocall -- the $name... and regexp... parts -- are ignored.
In effect, your filter is:
[search:text:regexp<$macrocall>]
and since there is no variable named "$macrocall", it is trying to match a blank pattern which,
of course, produces no results.
To actually get the rendered results of the validateregexp $macrocall, you need to use the
<$wikify> widget to process and capture the *output* of the validFilter() macro into a variable,
and then use that variable in the filter. Something like this:
<$wikify name="thefilter" text=<<validFilter>>>
...
[search:text:regexp<theFilter>]
...
</$wikify>
I hope this explanation doesn't make your head explode. :)
Let me know how it goes...
-e