06-21-2014, 03:23 PM | #1 |
Zealot
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
[Solved] function re()
Greetings,
I found in the forum, the way to replace the last point (".") from the author's firstname, like this : Code:
{#author_sort_firstname:re([.]$,)} (i believed that it used regex ?? and the [.] is before the $ ??) Second : I want to do the same, but for all points in the firstname, how to do this with the re() function ? Thanx in advance for your precious help... Last edited by myki; 06-23-2014 at 05:33 AM. |
06-21-2014, 04:08 PM | #2 | |
Well trained by Cats
Posts: 30,443
Karma: 58055868
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
|
|
Advert | |
|
06-21-2014, 04:38 PM | #3 |
Zealot
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
Thanx for your help Theducks.
In fact i am building my pattern for the "save as" option. I want to add the author's first name without points, without changing anything in my database, that's why i need to use the "re()" function. But the "quality check" plugin will help me for other things for sure Thank you ! Edit : the first name doesn't need to be extracted from author_sort, because it is allready stored in my personnal field #author_sort_firstname |
06-22-2014, 05:36 AM | #4 |
Ex-Helpdesk Junkie
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
That just uses the standard python regex re() module, running the regex "[.]$" and replacing it with "" -- the dot is surrounded by brackets to escape its special meaning as match-any-one-character, but you could do the same with "\.$" and of course, the Dollar sign matches the end-of-line border. So you are matching a dot (not any-character) followed by the end of the field.
A regex to match any dot would be "\." since it doesn't only look for the one right before the end-of-line border as indicated by "$". In order to better understand regex, you may wish to read a tutorial, like the one here: http://www.regular-expressions.info Last edited by eschwartz; 06-22-2014 at 05:39 AM. |
06-23-2014, 05:32 AM | #5 |
Zealot
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
Everything is clear now, thank you very much eschwartz
I only knew the "\" to escape a character, and i believed that the $ was to indicate a field to Calibre, like the $ in an expression like {series:'ifempty($,'{author_sort}')'}. |
Advert | |
|
06-23-2014, 12:09 PM | #6 |
Ex-Helpdesk Junkie
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Brackets are use to create character classes, like [a-z] for lowercase letters; as such, special characters like dot-match-all have no special meaning within the brackets.
Inside a character class, only \^]- have non-literal meanings. $ when inside a regex gets passed to the regex instead of being translated by calibre first. Last edited by eschwartz; 06-23-2014 at 12:18 PM. |
06-23-2014, 06:11 PM | #7 |
Zealot
Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
I see, [.] is not very "pure" but sometimes we get lost when we use a lot of \ and / so it can be useful to cheat a bit
May be you could help me with my other post, that don't seem to passionate peole lol It's a post still about regex. You can find it here : Change case in a regular expression Anyway, thank you very much for the explanations, it is always better that getting the solution too fast |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mini Search function? | AndrewH | Kobo Reader | 4 | 12-21-2013 12:20 PM |
Find function | doug38 | Ectaco jetBook | 3 | 03-07-2010 11:51 PM |
New MAP function? | Wetdogeared | Feedback | 2 | 03-03-2010 09:11 AM |
Sync function | rcuadro | Calibre | 11 | 11-29-2008 09:19 AM |
Is there a way to improve the look up function ? | enzo.sandrolini | Bookeen | 8 | 07-26-2008 01:10 PM |