View Single Post
Old 01-06-2013, 10:59 AM   #1
snipe2004
Junior Member
snipe2004 began at the beginning.
 
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:
Originally Posted by HarryT View Post
Try using a search string of:

<p>([0-9]*)</p>

and a replace string of:

<h3>\1</h3>

ie, with parentheses around the "search string" for the numbers.
So this seems very useful to me! I already adapted it to this :

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
I also tried many combinations such as :
1-1-\1
01/01/\1
01 janv. \1
but none of them had worked
Could you help me?
Thanks in advance,
Snipe
snipe2004 is offline   Reply With Quote