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 01-10-2022, 09:48 AM   #1
Varo
Junior Member
Varo began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jan 2022
Device: Galaxy S9+
Regex expression to edit series when saving books to disk not working.

Hello,

All my series have non-english characters in them and the english part is enclosed by square brackets.

Example of a series name: 魔法科高校の劣等生 [Mahouka Koukou no Rettousei]

I want to be able to change this using the template and only have the english part of the series name like this: Mahouka Koukou no Rettousei

Towards that end I tried using this:

Code:
{series:re('[^\x00-\x7F]+', '')}/{title}
It would replace all non english characters with nothing. However it does not seem to work. Additionally, if I try to also remove the square brackets in the regex expression like this:

Code:
{series:re('[^\x00-\x7F]+|\[|\]', '')}/{title}
I get an invalid format specifier error eventhough the regex exp should be fine.

Any help would be really appreciated.
Varo is offline   Reply With Quote
Old 01-10-2022, 11:06 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,926
Karma: 22669820
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
the regex runs on unicode not bytes. You want to use \uXXXX for unicode characters
kovidgoyal is offline   Reply With Quote
Advert
Old 01-10-2022, 11:12 AM   #3
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,876
Karma: 55267620
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Just capture each character type group and don't use that group in the replace

If you want to capture reserved symbols, they must be escaped:
Code:
(\[foo, bar\])
Replacements do not need to be in the order captured.
\2 - \5 - \1 (notice that I did not use \3 or \4)
theducks is offline   Reply With Quote
Old 01-10-2022, 01:34 PM   #4
Varo
Junior Member
Varo began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jan 2022
Device: Galaxy S9+
Quote:
Originally Posted by kovidgoyal View Post
the regex runs on unicode not bytes. You want to use \uXXXX for unicode characters
Quote:
Originally Posted by theducks View Post
Just capture each character type group and don't use that group in the replace

If you want to capture reserved symbols, they must be escaped:
Code:
(\[foo, bar\])
Replacements do not need to be in the order captured.
\2 - \5 - \1 (notice that I did not use \3 or \4)

Thank you very much. Combining advice from the both of you I achieved my goal with this:
Code:
{series: re([^\u0000-\u007F]+|[\u005B-\u005D]+, )}
Varo is offline   Reply With Quote
Reply

Tags
regex, regex-function, template editor


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving books to disk thomcuccureddu Library Management 0 03-18-2019 02:50 PM
Question about saving books to disk Ispanderion Library Management 8 08-25-2018 08:20 AM
Saving books to disk using {author_sort} DragonflyKing Library Management 5 09-26-2012 05:08 AM
Syntax for Saving Books to Disk Sea Dubya Calibre 2 04-05-2012 03:15 AM
Saving to Disk Multi Auth same series curiosity Library Management 2 05-27-2011 01:14 AM


All times are GMT -4. The time now is 04:45 PM.


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