01-18-2012, 03:07 AM | #1 |
Belgian Pommes Frites
Posts: 101
Karma: 532
Join Date: Jan 2012
Device: Pocketbook Touch HD
|
wildcards in search-replace sigil 0.4905?
Hi everyone,
I am a beginner in the world of ebooks. I bought my first ebook reader in dec 2011 (Bookeen Opus). Hence I also started to use sigil 0.4.2. recently. First of all, thanks to all the people that develop sigil. Very useful app. Thanks. I have been using search and replace a lot, especially with wildcards. Yesterday I installed Sigil 0.4.905 and wanted to use search-replace. But the wildcard option does not seem to be present anymore. Is this by design? Or not? I like wildcards. Regex seems to be very, very complicated. Last edited by Capricorn; 01-18-2012 at 03:12 AM. |
01-18-2012, 09:20 AM | #2 |
Wizard
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Regex is much better than wildcards and easier to control. Put some effort in it, and you will see the benefit.
|
Advert | |
|
01-18-2012, 09:45 AM | #3 | |
Well trained by Cats
Posts: 29,836
Karma: 54837878
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Go read Manichean's REGEX Tutorial: https://www.mobileread.com/forums/sho...d.php?t=118569 |
|
01-18-2012, 05:13 PM | #4 |
Belgian Pommes Frites
Posts: 101
Karma: 532
Join Date: Jan 2012
Device: Pocketbook Touch HD
|
Thank you for that info.
I had a read through manichean's tutorial. That was very useful. Then I went on to the python docs and got utterly lost. It seems like a complete programming language. As my purpose is to edit some epub books, and not programming, I decided there had to be a better way. Hence I searched on the internet for a regex generator. I did find some: 1. regexbuddy and regexmagic from the company Just Great Software 2. expresso from ultrapico As expresso was free, I decided to go for that one. Then I built the following regex, using expresso, for find and replace find: </p>[\s]+<p class="calibre2"> replace: \s When I executed this in sigil, it would find the string in my codeview file, but it did NOT replace it, when I pushed the single replace arrow. If I pushed the replace all button, it worked, but it put in the string \s instead of a blank space. If I used a blank space in the replace field, again, it did nothing on single replace, but on replace all button, it executed properly with a blank space. What am I doing wrong? |
01-18-2012, 05:24 PM | #5 | |
Well trained by Cats
Posts: 29,836
Karma: 54837878
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
replace single is broken in 905 |
|
Advert | |
|
01-18-2012, 06:22 PM | #6 |
Member
Posts: 19
Karma: 10
Join Date: Apr 2011
Device: kindle dx
|
2 things you did wrong
1. First you using the brackets instead of parentheses </p>(\s)+<p class="calibre2"> 2. For replacement you need to change \s to \1. \1 represents (\s) from find Need to learn about basic of regex. Last edited by congngo; 01-18-2012 at 06:27 PM. Reason: grammar |
01-19-2012, 02:51 AM | #7 |
Belgian Pommes Frites
Posts: 101
Karma: 532
Join Date: Jan 2012
Device: Pocketbook Touch HD
|
theducks: yes, it seems to be broken. I went back to sigil 0.4.2 and single replace worked again.
congngo: thanks for pointing this out. I went back to expresso and redid the regex. It turned out I had made mistakes, as I am still learning how the product works. Expresso this time produced the following: </p>\s+<p class="calibre2"> I put that string into the find of sigil 0.4.2. In replace neither \s or \1 worked. Just putting in the blank space by pressing the space bar on the keyboard did the trick. Replacing single items now works well with my regex, at least in sigil 0.4.2. If I will ever learn regex properly, is not certain at all, as it seems to be hours of work for something that should be simple (at least using basic wildcards). For now, I will continue to experiment with expresso, and keep searching for posts on regex in this forum. I assume once I have my collection of regex's that work for most things, it will be sufficient. Thanks for all the help. |
01-19-2012, 03:57 AM | #8 | |
♫
Posts: 661
Karma: 506380
Join Date: Aug 2010
Location: Germany
Device: Kobo Aura / PB Lux 2 / Bookeen Frontlight / Kobo Mini / Nook Color
|
Quote:
\1 will use the first match found in parantheses, but there were no parantheses. \s did not work because this is a placeholder for white spaces (e.g. blanks and tabs). You can't replace anything with \s since it is not a vaild character like the blank itself. On the other hand it should have worked with congngo's example </p>(\s)+<p class="calibre2"> and replace with \1 since in this case \1 represents the charatcer found by \s (note that this is NOT \s but a blank or a tab or whatever!) Last edited by WS64; 01-19-2012 at 04:01 AM. |
|
01-19-2012, 05:56 AM | #9 |
Belgian Pommes Frites
Posts: 101
Karma: 532
Join Date: Jan 2012
Device: Pocketbook Touch HD
|
WS64: thank you very much for that clarification. Now I understand the \1. It is just a variable that takes the value of whatever is in the brackets.
It also makes me understand that I will have to learn more about regex. Just using the expresso app is not enough. However, from the little bit I have read left and right, and understood, there seem to be many versions of regex. So, which version should I learn? And is it correct that calibre and sigil use different regex versions? |
01-19-2012, 06:15 AM | #10 |
♫
Posts: 661
Karma: 506380
Join Date: Aug 2010
Location: Germany
Device: Kobo Aura / PB Lux 2 / Bookeen Frontlight / Kobo Mini / Nook Color
|
oops, mixed up brackets and parantheses (it's not my native language...)
Glad you found out by yourself I learned regex by this excellent tutorial: http://www.regular-expressions.info/tutorial.html I am still not sure which regex version Sigil uses (especially since there was a change from 0.4.2 to 0.4905), but until you reach the differences its a long way, don't worry about this now. If unsure stick with the Perl 5 version, it's the most popular one. |
01-19-2012, 07:23 AM | #11 | |
Guru
Posts: 655
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
|
Quote:
|
|
01-19-2012, 08:14 AM | #12 | |
Sigil & calibre developer
Posts: 2,488
Karma: 1063785
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
|
Versions <= 0.4.2 use QRegExp. QRegExp is very limited and does not support a number of things. To name a fe: look behind, start of line ^ and end of line $. QRegExp is really off in it's own world and you're best bet is to study the QRegExp documentation to understand what it supports.
Versions >=0.4.901 use PCRE. Quote:
Sigil's regex support is pretty much everything Python and most things from Perl. For searching, I can't think of anything (other than embedding Perl code) that isn't supported. Replace does not support a few things: \Q, \x, \N, \o. |
|
01-19-2012, 12:13 PM | #13 |
Belgian Pommes Frites
Posts: 101
Karma: 532
Join Date: Jan 2012
Device: Pocketbook Touch HD
|
Ah...again great info.
Thanks. That tutorial will keep me occupied for many months and regex will probably give me some pretty bad headaches meanwhile. On to regex horizons...arrgghhh. |
01-19-2012, 08:22 PM | #14 |
Guru
Posts: 696
Karma: 150000
Join Date: Feb 2010
Device: none
|
PCRE is really not so bad if you take it in bite-sized doses. Stop when your brain reaches its softening point; don't wait 'till it melts. You can probably do most of what you want with very simple regular expressions.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Search & Replace "wildcards"? | LoveMyKobo | Calibre | 3 | 05-26-2011 06:12 PM |
search and replace - drops blanks in replace ? | cybmole | Conversion | 10 | 03-13-2011 03:07 AM |
Search and replace in 0.2.0 | paulpeer | Sigil | 7 | 03-13-2010 11:59 AM |
wildcards in sigil | bobcdy | Sigil | 2 | 12-18-2009 10:19 PM |
Why no search and replace? | charleski | Sigil | 10 | 11-24-2009 04:13 PM |