Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 03-15-2021, 05:32 AM   #1
jelzin
Junior Member
jelzin began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Apr 2014
Device: Kobo Aura HD
Custom column from tags

I try to create a custom column that contains a date value from the tags column. The format of that tag is 'year-month-day' (where the month and day will be padded with 0 to length 2) eg. 2021-03-15.

I tried this function to get it but it's not working and i can't figure out why (could be the regex or i'm using the wrong function here or all those ' are canceling themselfs out somehow?):

{:'list_re(field('tags'), ',' ,'\d{4}-\d{2}-\d{2}')'}

Would be nice if someone could help me out with this one.

The next problem will be to create a hierarchy from that date field:
Year.Month.Day

I know i could easily create an custom column with a hierarchy but i try to use the default columns and create automated custom columns from those.

Thanks,

Johan
jelzin is offline   Reply With Quote
Old 03-15-2021, 08:59 AM   #2
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: 11,942
Karma: 7219261
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Use
Code:
program: list_re(field('tags'), ',', '\d{4}-\d{2}-\d{1}', '')
The problem: the { and } characters can't reliably be used in Template Program Mode because the template parser thinks they are full templates.
chaley is offline   Reply With Quote
Advert
Old 03-15-2021, 12:31 PM   #3
jelzin
Junior Member
jelzin began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Apr 2014
Device: Kobo Aura HD
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!
jelzin is offline   Reply With Quote
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: 11,942
Karma: 7219261
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
Old 03-15-2021, 02:30 PM   #5
jelzin
Junior Member
jelzin began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Apr 2014
Device: Kobo Aura HD
Quote:
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.
This is a nice one-liner!
I'm not quite familiar with regular expressions but this one i do understand and i like it!
jelzin is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Genre Hierarchical Column to tags jjquin Library Management 5 03-02-2018 12:25 AM
How can I boolean OR several tags into one custom column? bmix Library Management 3 01-09-2015 03:57 AM
Download tags to a custom column atjnjk Library Management 8 01-18-2012 08:02 AM
Help with template for custom column from tags africalass Library Management 2 07-16-2011 11:47 AM


All times are GMT -4. The time now is 03:10 AM.


MobileRead.com is a privately owned, operated and funded community.