|
|
#1 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 14
Karma: 7220
Join Date: Dec 2012
Device: Kindle 4NT, Android
|
Template/Regular Expression Trouble
Hi,
I'm using a custom column to work with the Kindle Collections plugin. It collects author names in three groups ("A-I", "J-Q" and "S-Z"). A fourth ("other") is reserved for authors who might call themselves something like 123foo or $bar. The following code worked fine so far... Code:
program:
author_first_letter = substr(field('author_sort'), 0, 1);
group = switch(author_first_letter,
'[A-I]', 'A-I',
'[J-R]', 'J-R',
'[S-Z]', 'S-Z',
'other');
strcat('Authors ', group)
...until Karel Čapek came along. His books should be found in the "A-I" collection but are listed under "other". So I expanded the regular expression to Code:
[A-IĀ-IJ] But the colums and tag browser show it under "other". I also tried unicode: Code:
[A-I\u0100-\u0132] Being both 1) new to the calibre template language and 2) a regular-expression-avoider-whenever-I-can I assume that I made a mistake... but what puzzles me is that the Template value of the Edit template window shows the expected "Authors A-I" (at least in the first case, without unicode notation). Could this be a bug in Calibre? Last edited by bookworm2000; 01-01-2013 at 10:54 PM. Reason: typo |
|
|
|
|
|
#2 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,526
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You found a strange bug in calibre that has been lurking for many months. Character classes are not processed in unicode in compiled template functions, but *are* in interpreted template functions. Functions are interpreted when using the template editor. They are compiled for performance when used in composite columns.
I have submitted a fix that should be in the next release. In the meantime you can work around the problem by changing the tweak "Compile General Program Mode templates to Python" to False. |
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 14
Karma: 7220
Join Date: Dec 2012
Device: Kindle 4NT, Android
|
Thank you for the fast reply. That solved the problem.
|
|
|
|
![]() |
| Tags |
| regular expressions |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| More than 3 regular expression? | james968 | Conversion | 1 | 04-04-2012 06:39 AM |
| Regular Expression Help | Azhad | Calibre | 86 | 09-27-2011 03:37 PM |
| Regular Expression Help | smartmart | Calibre | 5 | 10-17-2010 06:19 AM |
| Help!! Having trouble with regular expression | Partzz | Calibre | 2 | 09-14-2010 01:32 PM |
| Help with the regular expression | Dysonco | Calibre | 9 | 03-22-2010 11:45 PM |