Function version could be something like this ? Someone can improve on it.
Have a great weekend !
\function substring.withDelimiters( str1, str2 )
[all[]] :map[function[search.string],<str1>,<str2>function[swap_param],<currentTiddler>]
\end
\function search.string( str1, str2 ) [[.*?]] [<str1>escaperegexp[]] [[(.*?)]] [<str2>escaperegexp[]] +[join[]]
\function line.feed() [charcode[10]]
\function swap_param( inputText )
[all[]] :map[<inputText>search-replace:g:regexp<line.feed>,[♭]search-replace:g:regexp<currentTiddler>,[$1┋]search[┋]search-replace:g:regexp[♭],<line.feed>split[┋]butlast[]format:titlelist[]join[ ]]
\end
<$let t="""
This is ^a very$ short ^sample$ text.
This is another very short sample ^text.
This is$ a third short sample text.
"""
>
t: <$text text=<<t>> /> <br><br>
output: {{{[<t>function[substring.withDelimiters],[^],[$]]}}}
t: This is ^a very$ short ^sample$ text. This is another very short sample ^text. This is$ a third short sample text.
output: [[[a very]] sample [[text. This is]]]