View Single Post
Old 03-15-2021, 12:41 PM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by jelzin View Post
Thanks chaley, you made my day!

I took it a step forward to create a hierarchy date format with this code:

Code:
program:
 list_split(list_re(field('tags'), ',', '\d{4}-\d{2}-\d{2}', '') , '-' , 'vars');
 strcat(vars_0,'.',vars_1,'.',vars_2)
This will change the extracted date (eg. 2021-03-15) to 2021.03.15

It may not be the nicest code but it works!
That is a nice use of list_split(). It makes it really easy to do post processing on the values. For example, you could easily add a hierarchy level for the decade or century.

Another quite similar way to do it would be to use the replacement pattern in list_re:
Code:
program: list_re(field('tags'), ',', '(\d{4})-(\d{2})-(\d{2})', '\1.\2.\3')
This implementation isn't better in any cosmic sense, but if someone is very familiar with regular expressions it might be easier to understand.
chaley is offline   Reply With Quote