Testing for the existence of a substring

Folks,

I belive I have solved this repeated times, but it is an issue with the documentation that I cant find the answer again. Consider I have a string of text such as {{My heading||inner-link|!!!}} maybe something, in fact it is a line in a tiddler text field.

So now I am writting a TiddlyWiki script that will use each line in which I can find ||inner-link| then I will do something with the whole line. So All I want to do is to test if the string {{My heading||inner-link|!!!}} maybe something to see if it contains the substring ||inner-link| and leave me with the full string. Similar to testing for prefix or suffix.

Of course you will quickly see the contains operator is more a “list contains filter” ie; filter the input by searching list fields for a value.

The search operator operates accross tiddlers and fields.

I know I may be able to use regular expressions but I want the oportunity to provide the substring via a literal, variable or transclusion (reference). I think this is a missing operator? contains-string[]?

  • Its fine if it is also the prefix, suffix, or only string.

I have created a contains-string[] operator based on the match[] operator and it works (tested)

  • Care of ChatGPT

You might want to take a look at: How to Extract Delimited Substrings from a Longer String - Tips & Tricks - Talk TW

1 Like

Mmm, something like this : [<list of strings>search:title<searchstring>] ?

More like this;

\define string() {{My heading||inner-link|!!!}} 
\define substring() ||inner-link|

{{{ [<string>contains-string<substring>] }}}

modules_filters_contains-string.js.json (1.7 KB)

warning this is my own script kiddy code.

\define substring() ||inner-link|

{{{ [all[current]get[text]splitregexp[\n]contains-string<substring>] }}}

list each line containing the substring.