The User Defined Extract Filter Operator

Following to [IDEA] Extract Feature in The TiddlyWiki Core - Discussion - Talk TW and the suggestion by @TW_Tones I developed a user defined filter operator extract.substring

Code

\procedure filter-pattern() ♭[\w|\s|\W]+?♭
\function search-pattern() =[<start>escaperegexp[]] ="([\w|\s|\W]+?)" =[<stop>escaperegexp[]] :and[join[]]

\function extract.substring(start, stop)
[search-replace:g:regexp<search-pattern>,[♭start♭$1♭stop♭]]
:and[split[♭start]split[stop♭]regexp<filter-pattern>search-replace:g[♭],[]]
\end extract.substring

<!--REMARKS
The unicode symbol used for substring border: &#9837;
Start and stop delimiter can be the same like @@Jeremy@@
-->

How it works

  • The extract.substring has two parameters, start delimiter and stop delimiter
  • The input is a selection of titles

Example
Extract all highlighted text. A highlighted word is the one delimited by two @@.

<$let myinput="@@TiddlyWiki@@ is an amazing piece of @@software@@.">

<$list filter="[<myinput>extract.substring[@@],[@@]]">
<$text text=<<currentTiddler>> /><br/>
</$list>
</$let>

This produces

TiddlyWiki
software

Demo

Alternative: An improved alternative to this filter operator with detailed documentation can be found here: How to Extract Delimited Substrings from a Longer String - #5 by jacng

2 Likes