Regex help please

Find all tidlers that have dates within their text in the form yyyy-mm-dd.
Find the earliest and the latest occurances (they will be both if only one date is found)
Some tiddlers already have fields named earliest and latest some will need to be created where dates are found.
Enter the dates found in fields ‘earliest’ and ‘latest’

You asked a very similar question 10 days ago:
https://talk.tiddlywiki.org/t/find-the-earliest-date-in-each-of-a-selection-of-tiddlers-text-field

Here’s the solution, which is just a variation on my reply to that previous question:

<$let re="(\d{4}-\d{2}-\d{2})">
<$button> extract earliest and latest dates
   <$list filter="[all[]search:text:regexp<re>]">
      <$set name=dates filter="[{!!text}splitregexp<re>search:title:regexp<re>sort[]">
      <$action-setfield earliest={{{ [enlist<dates>first[]] }}} latest={{{ [enlist<dates>last[]] }}}/>
      </$set>
   </$list>
</$button>

-e

edit: fixed typo “enist” → “enlist”

2 Likes

Thank you Eric, there is a typo in case anyone else is looking, in the second ‘enlist’ and I don’t know why but I get a message in the fields something like ’ there is an error in the filter [’’ , instead of the dates?

To save me annoying you again will it be possible to append the contents of the two fields ‘earliest’ to ‘latest’ to the title of each of their tiddlers in the form YYYY-MM-DD to YYYY-MM-DD if those titles do no already hold a date?