|
![]() |
|
Thread Tools | Search this Thread |
![]() |
#1 |
Connoisseur
![]() Posts: 60
Karma: 10
Join Date: Apr 2013
Device: Kindle Paperwhite 3 (Manga)
|
Possible to use regex to move age-level but not genre to a custom column?
Hello, I have populated my tags column with age-levels like 04-07, 05-10, 16-20 etc. along with genres like fairytale, picture book, animals
I would like to move the age-level to a new column. In the bulk search and replace, I can use a regex like Code:
(\b\d{2}-\d{2}\b) Code:
\1 but it copies the genre tags too... Any advice? Also, I would prefer to move them, instead of copy, if that is possible. Thanks! Last edited by iamagloworm; 09-14-2023 at 04:11 PM. |
![]() |
![]() |
![]() |
#2 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 112
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
|
my calibre is tied up right now or I'd actually try this, but... a regex like this might work:
find the books to update: Code:
tags:"~\b\d\d-\d\d\b" find: Code:
^(.*?)((\b\d\d-\d\d\b))+(.*?)$ Code:
\2, Code:
#myagetags This should be nondestructive to the original tags. After your satisfied it works, search field: tags find: Code:
\b\d\d-\d\d\b (i.e. replace with nothing) should strip the age tags. Or you could go into the tag manager and manually select them, then remove from there. Last edited by kjdavies; 09-14-2023 at 12:04 PM. Reason: improved regex, added 'remove from tags field' part |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Connoisseur
![]() Posts: 60
Karma: 10
Join Date: Apr 2013
Device: Kindle Paperwhite 3 (Manga)
|
Thanks for your help. That is how I would expect it to work, but it doesn't. I am wondering if it is something to do with calibre's separator characters
Code:
::: See the attached screenshot if. Am I missing something? |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
The problem is that for multiple valued columns like tags, search & replace iterates over the individual values (each tag). It doesn't operate on all of them at once. Thus the regular expression is applied to each tag, not the string of all tags.
You can get around this by using *template as the input field, where the template is something like {tags}. The result of a template is a single value, not multiple values, even if it contains commas. This causes S&R to operate on the single value, not individual ones. You could even get fancier and have the template generate the value you actually want in the destination column, eliminating the regex. This would be useful mostly if splitting apart the tags requires some logic & conditionals, which doesn't seem to be the case here. |
![]() |
![]() |
![]() |
#5 | |
Connoisseur
![]() Posts: 60
Karma: 10
Join Date: Apr 2013
Device: Kindle Paperwhite 3 (Manga)
|
Quote:
My cave-man workaround is just to exclude any books missing age-level tags... Attached is my config that mostly works: |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
This works for me. It depends on the tag always being nn-nn with no other leading or trailing characters. It uses the first one it finds. If it desn't find any then it returns '' The General Program Mode template is Code:
program: for t in $tags: if "^\d\d-\d\d$" in t then return t fi rof; return '' |
|
![]() |
![]() |
![]() |
#7 |
Connoisseur
![]() Posts: 60
Karma: 10
Join Date: Apr 2013
Device: Kindle Paperwhite 3 (Manga)
|
Awesome, thank you so much!
|
![]() |
![]() |
![]() |
#8 | |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 112
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
|
Quote:
If examining tags works on a per-tag basis... Oh. If the tag doesn't match the pattern, it'll still output the original value. You'll copy all the tags. On the other hand, and this would probably be pretty wasteful, wouldn't this work? Code:
find: ^(\d\d-\d\d)$ replace: \1 target: #agetag (concatenate at tags -- ::: inserted) Code:
find: ^(\d\d-\d\d)$ replace: target: tags (replace with nothing) (calibre is busy moving a bunch of files right now, or I'd actually try it and find out) |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
building a genre custom column from tags | meghane_e | Library Management | 3 | 03-09-2019 09:39 PM |
how to move tags data into a new custom column | smoothrolla | Library Management | 6 | 05-30-2018 07:19 AM |
Custom Genre Hierarchical Column to tags | jjquin | Library Management | 5 | 03-02-2018 12:25 AM |
Move selected data from series column to a new custom column | fvdham | Library Management | 3 | 06-02-2017 03:49 PM |
how to move value(s) of tag column to a custom made column | zoorakhan | Library Management | 0 | 12-08-2012 03:53 AM |