Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 12-20-2010, 06:29 AM   #1
veezh
plus ça change
veezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beauty
 
veezh's Avatar
 
Posts: 101
Karma: 32134
Join Date: Dec 2009
Location: France
Device: Kindle PW2, Voyage
Question: find and replace with variables?

Can anyone give me a clue about using variables in a calibre recipe?

I want to try to find any digit followed by a space and three other digits, for example '1 000', and replace the space with a non-breaking space.

I thought something like this would work:
Spoiler:

(re.compile(r'([0-9]) ([0-9])([0-9])([0-9])'), lambda match: '\1 \2\3\4'),


This finds the right expressions, but the variables aren't replacing correctly.

What am I doing wrong?

Last edited by veezh; 12-20-2010 at 07:30 AM.
veezh is offline   Reply With Quote
Old 12-20-2010, 12:08 PM   #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,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
use

r'\1 \2\3\4'


Note the r
kovidgoyal is offline   Reply With Quote
Advert
Old 12-20-2010, 03:49 PM   #3
veezh
plus ça change
veezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beauty
 
veezh's Avatar
 
Posts: 101
Karma: 32134
Join Date: Dec 2009
Location: France
Device: Kindle PW2, Voyage
Quote:
Originally Posted by kovidgoyal View Post
use

r'\1 \2\3\4'


Note the r
Thanks very much for your reply, Kovid.

I've just tried your suggestion, but I'm still getting the same result as before, i.e. that the strings are being found but are being replaced with the literal string I've supplied, not the variables.

As an example, the number '22 100' shows up as '2\1 \2\3\4' (the non-breaking space is correctly being added) in the files generated from the recipe.

Any other hints greatly appreciated!
veezh is offline   Reply With Quote
Old 12-20-2010, 04:22 PM   #4
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,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
oh right you're using a lambda, sorry, do this

lambda m: m.group(1) + ' ' + m.group(2) + m.group(3) + m.group(4)
kovidgoyal is offline   Reply With Quote
Old 12-21-2010, 05:23 AM   #5
veezh
plus ça change
veezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beautyveezh does all things with Zen-like beauty
 
veezh's Avatar
 
Posts: 101
Karma: 32134
Join Date: Dec 2009
Location: France
Device: Kindle PW2, Voyage
Thanks a lot, Kovid. It's working!
veezh is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find / replace bremler Sigil 6 12-17-2010 03:26 PM
REGEX find and replace help please potestus Sigil 13 09-18-2010 04:14 PM
find and replace, epub ampsonic Reading and Management 3 03-02-2010 03:20 AM
Crashes on find / replace all mr ploppy Sigil 1 02-03-2010 12:35 PM
Using Find/Replace with BD Otter Sony Reader 7 02-28-2009 01:49 PM


All times are GMT -4. The time now is 06:40 PM.


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