Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 09-03-2011, 12:00 AM   #1
kmckinley
Member
kmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-books
 
Posts: 15
Karma: 954
Join Date: Aug 2011
Device: NOOK Simple Touch
Replacing multiple tags over 2 lines

I have the following source:

Code:
    <p class="calibre10"><span class="calibre12 bold">15</span></p>

    <p class="calibre2"><span class="calibre4 bold">MAVERICKS</span></p>
I would like to replace all that stuff with
Code:
    <h1>15<br />
    MAVERICKS</h1>
The regular expression for the first line appears to be
Code:
(Find)<p class="calibre10"><span class="calibre12 bold">(\d\d)</span></p>
(Replace with)<h1>\1<br />
Would it be possible to do the search and replace for the second line in the same pass?
kmckinley is offline   Reply With Quote
Old 09-03-2011, 02:32 AM   #2
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
Posts: 2,742
Karma: 2117255
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-300, PRS-T1
I think the following might work:

find:
Code:
<p class="calibre10"><span class="calibre12 bold">([0-9]{1,})</span></p>\s<p class="calibre2"><span=class="calibre4 bold">([A-Za-z]{1,})</span></p>
replace by:
Code:
<h1>\1<br />\2</h1>
There are more ways to do this of course.
Toxaris is offline   Reply With Quote
Old 09-03-2011, 02:45 AM   #3
kmckinley
Member
kmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-books
 
Posts: 15
Karma: 954
Join Date: Aug 2011
Device: NOOK Simple Touch
Quote:
Originally Posted by Toxaris View Post
I think the following might work:
...
There are more ways to do this of course.
I only need one.

Unfortunately that doesn't do it. The first part of the expression matches, but adding the second fails.

According to some old docs, Sigil's RegEx engine is very Perl-like. Perl doesn't normally do multi-line matches, but it can be made to do so. I wonder if we must do something special for multi-line matches.
kmckinley is offline   Reply With Quote
Old 09-03-2011, 03:33 AM   #4
Perkin
Guru
Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.
 
Perkin's Avatar
 
Posts: 639
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD
Change Toxaris' find to

Code:
<p class="calibre10"><span class="calibre12 bold">(\d+)</span></p>\s+<p class="calibre2"><span class="calibre4 bold">(.+)</span></p>
The replace will be the same.
Perkin is offline   Reply With Quote
Old 09-03-2011, 07:21 AM   #5
Jabby
Jr. - Junior Member
Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.
 
Posts: 560
Karma: 2000170
Join Date: Aug 2010
Location: East Texas
Device: Archos, Asus, HP, Lenovo, Nexus and Samsung tablets in 7,8 and 10"
Quote:
Originally Posted by Perkin View Post
Change Toxaris' find to

Code:
<p class="calibre10"><span class="calibre12 bold">(\d+)</span></p>\s+<p class="calibre2"><span class="calibre4 bold">(.+)</span></p>
The replace will be the same.
In the above example, what would be the difference between (.+) and (.*). The various tutorials I've read talk about "greedy", "non-greedy", "lazy" and "reluctant" but I can't figure out precisely what they mean. What about \s* instead of \s+ - would that work?

Just trying to figure this regex stuff out.

Regards - John
Jabby is offline   Reply With Quote
Old 09-03-2011, 08:04 AM   #6
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 2,360
Karma: 1048182
Join Date: Sep 2010
Device: Kobo aura HD, Kobo Arc, Sony T2, Kindle Fire HDX 8.9 , Kindle for PC
i usually use \s* & it works fine .
I think the relevant definitions are:
\s+ match one or more spaces
\s* match none or more spaces
cybmole is online now   Reply With Quote
Old 09-03-2011, 08:15 AM   #7
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
Posts: 2,742
Karma: 2117255
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-300, PRS-T1
Forgot the plus sign...
Toxaris is offline   Reply With Quote
Old 09-03-2011, 10:34 PM   #8
kmckinley
Member
kmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-bookskmckinley has learned how to read e-books
 
Posts: 15
Karma: 954
Join Date: Aug 2011
Device: NOOK Simple Touch
That works beautifully.

An hour's work in seconds -- regexes rule!
kmckinley is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Touch Dark lines between lines of text taming Kobo Reader 12 06-13-2011 07:20 PM
Replacing tags after using them hiperlink Recipes 2 03-28-2011 10:23 AM
Common tags for multiple librairies poco06 Calibre 5 11-19-2010 01:51 AM
Multiple Tags luthar28 Kindle Formats 0 08-05-2010 10:18 PM
Bug: entries with multiple formats trigger multiple conversions flinx1 Calibre 12 05-21-2010 06:23 AM


All times are GMT -4. The time now is 06:09 AM.


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