Search for "[ ]" using Wikitext Filter?

is it possible to search for the string literal “[ ]” (space in the middle) using Wikitext filter syntax? I have searched around a bit and toyed around with it but I keep getting a syntax error; do I need to use a special escape code or ULR encode it or something? let me know your thoughts; thanks.

The problem is that the [ and ] chars are used as delimiters for the filter syntax itself, so you can’t use them as literal values in a filter.

The common workaround is to define a variable containing the desired search string, and then reference that variable in the filter syntax. Something like this:

<$let myVar="[ ]">
{{{ [all[]search:text:literal<myVar>] }}}

Note that you MUST use the :literal flag or the [ and ] will be seen as separate “tokens” that will match all instances of "[" OR "]" rather than instances of exactly "[ ]"

-e

Thanks, it’s kind of interesting to me there isn’t a designated escape character for filtersyntax! Like backtick in power shell

Then you could do like search ``[ ` ]`

Or maybe filters could support expand “URI-encoded” characters like ones that start with %?

You could use a regexp search with hex codes, like this:

{{{ [all[]search:text:regexp[\x5B \x5D]] }}}

-e

Oh I like that a bit better, though I assume the regex isn’t as performant as the native filters?

I have not heard any suggestion regexp is less performant, also a common pattern is to combine erics two suggestion set the regular expression in into a variable and name that in the filter search:text:regexp<regexp-string>]

In truth LLM’s are now quite good at helping here now;

I asked "The regular expression to Search for [ ]?

The following answers can typical be used by setting the regexp-string variable as an example and you do not need to worry about other filter syntax issues.

If you want to match the literal text [ ] (including the brackets and the space inside), you need to escape the square brackets because they have special meaning in regex:

\[\ \]

Explanation

  • \[ → literal opening bracket
  • \ → a space
  • \] → literal closing bracket

Common variations (depending on intent)

1. Match [ ] exactly (one space inside):

\[\ \]

2. Match brackets with any whitespace inside ([ ], [ ], etc.):

\[\s*\]

3. Match brackets with anything inside (non-greedy):

\[.*?\]

4. Match an empty character class [] (rare edge case):

\[\]

(Note: some regex engines treat this as invalid)


If you’re using this in a specific context (JavaScript, TiddlyWiki filters, etc.), tell me and I can tailor the exact syntax (escaping often changes slightly).

  • Not tested by me