View Single Post
Old 09-15-2023, 12:36 PM   #8
kjdavies
Zealot
kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.kjdavies is no e-book dilettante.
 
Posts: 112
Karma: 53342
Join Date: Jun 2013
Device: Sony PRS-600
Quote:
Originally Posted by chaley View Post
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.
That's what I get for not trying it (calibre was busy doing something).

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)
Then to remove the other tags, I'd probably go to the tag manager, but I suspect the regex replace below could work (probably slowly)

Code:
find: ^(\d\d-\d\d)$
replace:
target: tags (replace with nothing)
If I'm not mistaken -- and I totally could be -- the empty tags should drop out and leave you with just the not-empty tags.

(calibre is busy moving a bunch of files right now, or I'd actually try it and find out)
kjdavies is offline   Reply With Quote