12-20-2010, 06:29 AM | #1 |
plus ça change
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:
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. |
12-20-2010, 12:08 PM | #2 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
use
r'\1 \2\3\4' Note the r |
Advert | |
|
12-20-2010, 03:49 PM | #3 |
plus ça change
Posts: 101
Karma: 32134
Join Date: Dec 2009
Location: France
Device: Kindle PW2, Voyage
|
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! |
12-20-2010, 04:22 PM | #4 |
creator of calibre
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) |
12-21-2010, 05:23 AM | #5 |
plus ça change
Posts: 101
Karma: 32134
Join Date: Dec 2009
Location: France
Device: Kindle PW2, Voyage
|
Thanks a lot, Kovid. It's working!
|
Advert | |
|
|
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 |