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

Go Back   MobileRead Forums > E-Book Formats > Workshop

Notices

Reply
 
Thread Tools Search this Thread
Old 10-09-2012, 10:10 AM   #1
ghostyjack
Guru
ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.
 
ghostyjack's Avatar
 
Posts: 718
Karma: 1085610
Join Date: Mar 2009
Location: Bristol, England
Device: PRS-T1, 1825PT, Galaxy Tab, One X, TF700T, Aura HD, Nexus 7
Regex problem: Trying to replace surrounding text without effecting the middle

I'm trying to change the formatting on a book I'm working on.

At the beginning of each chapter, there is a chapter number, followed by a heading that is unique to each chapter. Underneath the heading is the start of the actual text.

The problem I have is that the text currently begins with <p> and I want to change it to <p class="newscene2">.

As this book as over 300 chapters, I didn't want to have to manually change each one. So what I want to do is to be able to search for for both the heading and the next <p> irespective of the content of the heading line and then replace the <p> with my new tag, but leave the content between intact.

I've found that:

Code:
<p class="heading">.+</p>

  <p>
will locate each entry, but I can't fathom the replace command. I've tried:

Code:
<p class="heading">.+</p>

  <p class="newscene2">
but all it does is replace all the content with .+ and not leave all the text alone.

So what am I doing wrong?
ghostyjack is offline   Reply With Quote
Old 10-09-2012, 10:57 AM   #2
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
You need to enclose the chapter number variable in parentheses. (I used \d+ because it searches for numbers.) Try:

Find:
Code:
<p class="heading">(\d+)</p>\n\n  <p>
Replace:

Code:
<p class="heading">\1</p>\n\n  <p class="newscene2">
BTW, since it's a heading, I'd recommend enclosing it in heading tags, which will allow you to automatically generate a TOC in Sigil. You could also combine both headings. For example:

Find:
Code:
<p class="heading">(\d+)</p>\n\n  <p>(.*?)</p>
Replace:
Code:
<h3 class="heading" title="\1 – \2">\1<br /><span class="newscene2">\2</span></h3>
Note: The above regex should work in Sigil 0.53 because it automatically adds two spaces and a line break between the two paragraphs. If you use a regular text editor, simply delete the spaces and the line-break characters (\n) in the regexes.

Last edited by Doitsu; 10-09-2012 at 11:05 AM.
Doitsu is offline   Reply With Quote
Advert
Old 10-09-2012, 01:51 PM   #3
ghostyjack
Guru
ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.
 
ghostyjack's Avatar
 
Posts: 718
Karma: 1085610
Join Date: Mar 2009
Location: Bristol, England
Device: PRS-T1, 1825PT, Galaxy Tab, One X, TF700T, Aura HD, Nexus 7
Thanks, thats useful, but in this case.

The chapter number is above it in h2 tags with a title line in that is used for the toc.

The heading line (of should I say subheading?) is going to be in a different style to the Chapter number, hence the separate lines.

Beside, I don't want to change the heading part, I want to change the line directly below it. The problem being is that that line just has a <p> tag at the start, just like most of the lines in the chapter so there is nothing to distinguish it from all the others.

As this <p> tag is the only one that has a <p class="heading"> tag above it, I thiugh it would be useful to search for all the <p class="heading"> with a <p> below it and then only change the <p> to <p class="newscene2">. I don't want the heading line changed.

What I have now:

Code:
<h2 id="ch01" title="Chapter One: This is a heading">One</h2>

<p class="heading">This is a Heading</p>

<p>Blah blah blah</p>
I want it to change to:

Code:
<h2 id="ch01" title="Chapter One: This is a heading">One</h2>

<p class="heading">This is a Heading</p>

<p class="newscene2">Blah blah blah</p>
ghostyjack is offline   Reply With Quote
Old 10-09-2012, 04:26 PM   #4
ghostyjack
Guru
ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.ghostyjack ought to be getting tired of karma fortunes by now.
 
ghostyjack's Avatar
 
Posts: 718
Karma: 1085610
Join Date: Mar 2009
Location: Bristol, England
Device: PRS-T1, 1825PT, Galaxy Tab, One X, TF700T, Aura HD, Nexus 7
I didn't quite get what you were refering to and couldn't try it.

I've now had a chance and by changing it to:

Code:
<p class="heading">(.+)</p>\n\n  <p>
and replace with:

Code:
<p class="heading">\1</p>\n\n  <p class="newscene2">
it seemed to work.

This found the instances and made the correct replacement without effecting the text in the heading.

Thanks very much for this.
ghostyjack 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
regex search/replace Sharlene Sigil 10 01-28-2012 04:14 AM
regex replace??? schuster Conversion 14 01-29-2011 09:02 AM
RegEx find and replace iblesq Sigil 1 01-10-2011 09:26 PM
need regex help search and replace schuster Calibre 4 01-10-2011 09:00 AM
REGEX find and replace help please potestus Sigil 13 09-18-2010 04:14 PM


All times are GMT -4. The time now is 05:35 AM.


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