Regular expressions to search for any tiddler title, and only that title

Hi I wanted to search all text fields for the a string in a variable such as <<currentTiddler>> for example $:/tags/ViewTemplate but a standard search returns tiddlers that include $:/tags/ViewTemplate/something or $:/tags/ViewTemplatesomething.

In this case since $ and / are special characters we have to use the “escaperegexp Operator” however if this was a tiddler title with any other valid characters in it, some of those will need to be escaped. And as you know there are not many restrictions on tiddler titles.

Warning: avoid using any of the characters | [ ] { } in tiddler titles

But now the question is how can we reliably construct a regular expression that can test for a variable title name and not when it is only part of the title. How can we detect where the string ends if we are permitted to use most characters in a tiddler title?

  • We can assume any of these | [ ] { } represent the start or end of a title, along with whitespace newlines there are other characters that may indicate string is a substring of a longer name.
  • We need to both escape the string but also add more regular expression codes around that string.

So I am not sure how to do this?

Any assistance appreciated.

This should do it. Detailed regexp info can be found at https://regexp.info

^ … start of text
$ … end of text
(?i) … TW specific → case insensitive

trim[] … eliminates leading and trailing spaces in user input

\function f.getRegexp() "^" [{input}trim[]escaperegexp[]] "$" "(?i)" +[join[]]

<$edit-text tiddler="input" class="tc-max-width" tag="input"/>

<<f.getRegexp>>

<$list filter="[all[shadows+tiddlers]] :filter[<currentTiddler>regexp<f.getRegexp>]" >
<<currentTiddler>>
</$list>