![]() |
#1 | |
Junior Member
![]() Posts: 8
Karma: 10
Join Date: Jan 2013
Device: Pc - Linux - Calibre
|
Desperately Looking for a Regex
Hi guys,
I'm desperately looking for a regex which would automatically search in my eBooks' titles the string "2012" (for example) and put it in my pubdate field. And, once this is done, I would also like it to replace some other fields like this, but the pubdate is the hardest for me. Let me show you an example : The pdf file is : TitleOfTheSerie Volume1 Number1 (out of 3) (2012) I would like to use the Search&Replace function of Calibre to extract those informations and put them in the correct place. So : 2012 -> pubdate (I'll use january everytime) TitleOftheSerie -> Serie Number -> Serie[X] Quote:
Search in : title For : ([0-2][0-9][0-9][0-9]) And replace it by : janv. \1 In : pubdate But I get an error : Code:
unknown string format calibre, version 0.9.11 ERREUR : Echec: unknown string format Traceback (most recent call last): File "/usr/lib/calibre/calibre/gui2/dialogs/metadata_bulk.py", line 125, in do_one_safe self.do_one(id) File "/usr/lib/calibre/calibre/gui2/dialogs/metadata_bulk.py", line 290, in do_one self.s_r_func(id) File "/usr/lib/calibre/calibre/gui2/dialogs/metadata_bulk.py", line 851, in do_search_replace setter(id, val, notify=False, commit=False) File "/usr/lib/calibre/calibre/library/database2.py", line 2613, in set_pubdate dt = parse_only_date(dt) File "/usr/lib/calibre/calibre/utils/date.py", line 94, in parse_only_date ans = parse_date(raw, default=default, assume_utc=assume_utc) File "/usr/lib/calibre/calibre/utils/date.py", line 80, in parse_date dt = parse(date_string, default=default, dayfirst=parse_date_day_first) File "/usr/lib/python2.7/dist-packages/dateutil/parser.py", line 697, in parse return DEFAULTPARSER.parse(timestr, **kwargs) File "/usr/lib/python2.7/dist-packages/dateutil/parser.py", line 303, in parse raise ValueError, "unknown string format" ValueError: unknown string format 1-1-\1 01/01/\1 01 janv. \1 but none of them had worked ![]() Could you help me? Thanks in advance, Snipe |
|
![]() |
![]() |
![]() |
#2 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,888
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Dates are tricky. I think that this is because of Locale rules coming into play.
Next: Mon Year (in any order) is not a valid date . You need all 3 of DD MM YYYY: 01 Jan 2012 Next is where you use the pattern: Preferences:Adding Books or The Metadata Editor (Bulk mode) ![]() TitleOfTheSerie Volume1 Number1 (out of 3) (2012) (.+) (\(.+\))\s*\(([\d]{4})\) Notes: (*not tested) Group 1 is everything up to the space before the first ( Group 2 is the (out of ... ) pay attention to the escaped ( and ) Group 3 is the 4 digit only Year with the ( ) discarded , again pay attention to the escaped ( ) You are on you own constructing the replacement (used on the Published destination field) pattern (date in your Locale's format). ![]() |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
US Navy, Retired
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,889
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Kindle PaperWhite SE 11th Gen
|
Moderator Notice
Moved posts to their own thread. @snipe2004 Please avoid hijacking threads with off topic info requests. When in doubt start a new thread. |
![]() |
![]() |
![]() |
#4 |
Junior Member
![]() Posts: 8
Karma: 10
Join Date: Jan 2013
Device: Pc - Linux - Calibre
|
Theducks, you're the King *_*
Thank you sooo much! It works like a charm!! (and, sorry Dr!!) [EDIT] If needed : Theducks solution works out-of-the-box to extract the pubdate frome title. To extract series frome title : Search : (\w) (V[0-9]*) (\#)([0-9]*) (\(.+\))\s*\(([\d]{4})\) in Title Replace : \1 [\4] in Series Last edited by snipe2004; 01-09-2013 at 01:03 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Legal advice desperately needed | Fluribus | Lounge | 3 | 11-27-2012 08:25 AM |
Desperately seeking expert (hired) help | illustrata | Writers' Corner | 7 | 06-06-2011 05:15 AM |
iLiad Desperately need Advise/Help ... Iliad charging issue.... | aabeg100 | iRex | 15 | 07-09-2010 12:16 PM |
Desperately Seeking Software for Digitizing Books. | harryE123 | Reading and Management | 8 | 12-17-2008 08:33 PM |
iTouch -- info desperately needed | Berni | Apple Devices | 36 | 10-05-2008 12:21 AM |