|
![]() |
|
Thread Tools | Search this Thread |
![]() |
#1 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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> Code:
<p class="heading">.+</p> <p class="newscene2"> So what am I doing wrong? |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
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> Code:
<p class="heading">\1</p>\n\n <p class="newscene2"> Find: Code:
<p class="heading">(\d+)</p>\n\n <p>(.*?)</p> Code:
<h3 class="heading" title="\1 – \2">\1<br /><span class="newscene2">\2</span></h3> Last edited by Doitsu; 10-09-2012 at 11:05 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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> 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> |
![]() |
![]() |
![]() |
#4 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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> Code:
<p class="heading">\1</p>\n\n <p class="newscene2"> This found the instances and made the correct replacement without effecting the text in the heading. Thanks very much for this. |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |