I am trying to match a text string from a field. For example, link (0000), where I am trying to match the last “)” and then trim the last seven characters. Not all of my links will need to remove the (0000) part.
<$link to={{!!field-name}}>
<$text text={{{ [<currentTiddler>get{!!field-name}]match[)]trim[7] :else{!!field-name}] }}}/>
</$link>
Try this:
<$text text={{{ [<currentTiddler>get{!!field-name}suffix[)]split[]butlast[7]join[] :else[{!!field-name}] }}}/>
Notes:
- You had some misplaced or missing open/close brackets.
-
match[...] compares the entire input text. suffix[...] compares just the trailing input text.
-
trim[...] parameter is text to remove, not a character count. Instead, use split[] to convert the input text into a list of separate characters, then use butlast[n] to remove n trailing list items, then join[] the remaining list items to convert them back to a single text string.
enjoy,
-e
I had to remove [<currentTiddler>get to get any output. But now it won’t work with :else{!!field-name}], and I did find that missing bracket at the end.
I can get it to work like this:
<$text text={{{ [{!!field-name}suffix[)]split[]butlast[7]join[]] }}}/>
I cheated, but it works:
<$link to={{!!field-name}}>
<$text text={{{ [{!!field-name}suffix[)]split[]butlast[7]join[]] }}}/>
<$text text={{{ [{!!field-name}!suffix[)]] }}}/>
</$link>
ah ha! I see where things went sideways… in the filter you originally posted, you wrote:
<$text text={{{ [<currentTiddler>get{!!field-name}... }}}/>
Where get{!!field-name} means: get the value of a field whose NAME is stored in another field called “field-name”. However, I can see from your last post (the one that worked for you), you are actually getting the value directly from the field named “field-name” (i.e., {!!field-name}).
So, to do what you want without “cheating”, you could use get[field-name] instead of get{!!field-name} so the filter would be something like this:
<$text text={{{ [<currentTiddler>get[field-name]suffix[)]split[]butlast[7]join[] :else[{!!field-name}] }}}/>
-e