Thread: Regex examples
View Single Post
Old 02-25-2014, 06:09 AM   #297
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by roger64 View Post
But the predictable pattern is that there can be from one to four successive
Code:
<p class="quote">
to enclose within a div.
I'm petty sure that there's a more elegant solution, but I'd use a simple two step approach in Sigil (I'm not sure if this works with Calibre Editor):

1. Insert opening <div> before first quote paragraph:

Find:<p>(.*?)</p>\s*<p class="quote">
Replace:<p>\1</p>\n<div class="quote">\n<p class="quote">

2. Insert closing </div> after last quote paragraph:

Find:<p class="quote">(.*?)</p>\s*<p>
Replace:<p class="quote">\1</p>\n</div>\n<p>

Obviously this only works if there's at least one non-quote paragraph before the first and after the last quote paragraph.
Doitsu is offline   Reply With Quote