Filter search for whole words only

Hey folks! I’m having some difficulty getting a filter search to work. My goal is to create keyword tiddlers that collate blogposts mentioning the title of that tiddler, but using neither the ‘literal’ nor ‘regexp’ flag will turn out a list that matches whole words. I’m only getting lists of tiddlers that contain the string of the keyword, even if it’s within other words.

Here’s my code:

<ul>
<$list filter="[search:text:literal<currentTiddler>!<currentTiddler>!sort[created]]">
<li><$link/></li>
</$list>
</ul>

Give this a try:

<$let re={{{ "(^|\s+)" [<currentTiddler>escaperegexp[]] "(\s+|$)" +[join[]] }}}>
<ul>
<$list filter="[search:text:regexp<re>!<currentTiddler>!sort[created]]">
<li><$link/></li>
</$list>
</ul>
</$let>

Notes:

  • the $let constructs a variable containing a regular expression pattern that matches:
    • start of text OR at least one whitespace character
    • followed by the current tiddler’s title
    • followed by at least one whitespace character or end of text
    • escaperegexp[] is applied to the current tiddler’s title so it is handled as a literal, even if contains a regexp pattern
  • The $list filter then uses search:text:regexp<re>to find the pattern within any tiddler text

-e

This works perfectly, thank you! I’ve managed to get some really fun customisation going for my wiki but I’m not familiar with more complex (to me) coding concepts, so I find myself stalling on things I think should be easier than they really are. Appreciate the help.

A related tool here to draw your attention to is the core plugin Freelinks which allows “linkification” of titles found in the body of displayed tiddlers. For large wikis perhaps only activate when exploring the details of content or use the plugin settings and a “Filter defining tiddlers to which freelinks are made”.