How to match substrings

How do I match a substring from a previous filter result? Maybe I am thinking to complicated but regexp gives me a really hard time here. Trying to create a suggestion list similar to how the fields dropdown work in Tiddler edit mode. Since I want to match case insensitive I have to construct the regular expression beforehand.

Json-Tiddler:

title: foo
record: item
type: application/json

{ "name": "myname", "location": "somewhere", "age": "too old" }

Now I have this construct:

# <temp> is an edit-text target tiddler
<ul>
	<$list filter="[<temp>get[key]]" variable="key">
		<$set name="pattern" value="(?i)<<key>>">
		<!--<$set name="pattern" value="[(?i)<<key>>]">--> #same results
			Key: <<key>>
			Pattern: <<pattern>>

			SHOULD: {{{ [indexes[]regexp[(?i)n]] }}} # returns the expected result

			Result1: {{{ [indexes[]regexp<pattern>] }}} # blank
			Result2: {{{ [indexes[]regexp[<pattern>]] }}} # blank
			Result3: {{{ [indexes[]regexp[(?i)<key>]]}}} # blank

			<$list filter="[record[item]!is[system]indexes[]] -[<key>] +[regexp<pattern>] +[sort[]]">
				<li><$link overrideClass="tc-tiddlylink" /></li>
			</$list>
		</$set>
	</$list>
</ul>

When entering ā€œnā€ into the edit-text I expect this result:

  • name
  • location

However I do not get any results and am banging my head for hours on end.

Hi,
I think your definition of pattern does not work like you expect. To concatenate two strings (one is a variable), use a filter like so:

<$set name="pattern" filter="[[(?I)]] [<key>] +[join[]]" select="0">

or

<$let pattern={{{ [[(?I)]] [<key>] +[join[]] }}}>

Then, Result1 should show the expected result. The syntax of Result2 and Result3 is invalid.

Have a nice day
Yaisog

PS: You could check that pattern has the correct value with a $log widget (output to the browser console) like this:

<$log pattern=<<pattern>> />

Just put this line somewhere inside the $set widget.

You may be interested in my keyvalues plugin: KeyValues ā€” advanced data-tiddler functions that should make working with data-tiddlers a bit easier.

May be there is something you could use

Thank you! Indeed I did expect the variable key to be substituted when calling the set macro. Works like a charm now.

Hi Mario, yes I am using your plugin in a few places already, thanks a lot! :slight_smile:

1 Like