Move snippet of text field into custom field

113 views
Skip to first unread message

History Buff

unread,
Aug 23, 2020, 12:46:40 PM8/23/20
to TiddlyWiki
All,

I'm just starting to look at this, but I thought I would ask the great community if anyone has done this before to prevent me from going down the wrong path.

What I would like to do is to search for a key phrase in the text field of all tiddlers and for those tiddlers where that phrase exists, move the next x number of characters into a custom field.

Specifically, I would like to search for the phrase "Charter Filed: " and then move/copy the date which follows (in the format of yyyy-mm-dd) into a custom field named charterfiled.

I think this should be doable and should save me a lot of manual work in the long run.

Any ideas?

Thanks in advance for the help.

Damon

Mark S.

unread,
Aug 23, 2020, 3:54:16 PM8/23/20
to TiddlyWiki
Here's a lister that will match and extract these dates, assuming there's only one per tiddler and that each date is formatted correctly. 

If it works, then the next step would be to make a button that would wikify the resulting date and stick it into the desired field.

Maybe someone else would get excited about that next step?

This could probably be done in only one or two list filters if PR2963 were implemented.

<$list filter="[regexp:text[Charter Filed:]]-[<currentTiddler>]" >
<$list filter="[all[current]get[text]splitbefore[Charter Filed:]]" variable="prefix">
<$list filter="[all[current]get[text]removeprefix<prefix>]" >
<$list filter="[all[current]split[-]nth[1]]" variable=year>
<$list filter="[all[current]split[-]nth[2]]" variable=month>
<$list filter="[all[current]split[-]nth[3]]" variable=daze>
<$list filter="[<daze>split[]nth[1]]" variable=d1>
<$list filter="[<daze>split[]nth[2]]" variable=d2>
<<year>>-<<month>>-<<d1>><<d2>>
</$list>
</$list>
</$list>
</$list>
</$list>
</$list> 
</$list> 
</$list> 

History Buff

unread,
Aug 23, 2020, 4:07:59 PM8/23/20
to TiddlyWiki
Thanks Mark,

It works great. I'm going to start looking into the next step. I will say that I would have definitely gone down the wrong road with the way I was thinking. Thanks so much!

Damon

Eric Shulman

unread,
Aug 23, 2020, 5:24:35 PM8/23/20
to TiddlyWiki
On Sunday, August 23, 2020 at 1:07:59 PM UTC-7, History Buff wrote:
It works great. I'm going to start looking into the next step.

Here's a version that optimizes Mark's filtering method and provides the next step (a button that sets the "charterfiled" field):
<$button> extract charter dates
<$list filter="[search:text[Charter Filed:]]-[
<currentTiddler>]" variable="tid" >
<$list filter="[
<tid>get[text]split[Charter Filed:]nth[2]splitregexp[\s]!match[]nth[1]]" variable="date">
<$action-setfield $tiddler=<
<tid>> charterfiled=<<date>> />
</$list></$list></$button>

The first $list finds all tiddlers that contain "Charter Filed:".  Then, for each tiddler found, the second $list gets all text following "Charter Filed:", splits on whitespace, ignores any leading whitespace, and gets the first text, which should be the date text, regardless of format.  This text is then written to the "charterfiled" field of the current tiddler.

enjoy,
-e

History Buff

unread,
Aug 23, 2020, 5:36:59 PM8/23/20
to TiddlyWiki
Thanks Eric,

That worked just perfectly! Now I have to study it closely so that I can understand how it works. Thanks for the explanation at the end.

Damon

History Buff

unread,
Aug 23, 2020, 7:01:29 PM8/23/20
to TiddlyWiki
I have taken the basic idea of Eric's and Mark's and extended it to many other items such as charter volume and charter pages as well as setting the state the charter was filed in.

Thanks again!!

Damon

Reply all
Reply to author
Forward
0 new messages