|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 679
Karma: 1085478
Join Date: Mar 2009
Location: Bristol, England
Device: PRS-600, Acer 1825PT, Galaxy Tab, PRS-T1, HTC One X, TF700T
|
Regex problem: Trying to replace surrounding text without effecting the middle
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?
__________________
Get 5GB of online storage for free from SugarSync. Click here for an additional 500MB to give you 5.5GB for free. Always have your stuff when you need it with @Dropbox. 2GB account is free! Click here Currently working on updating some of my Lovecraft work after receiving some corrections |
|
|
|
|
|
#2 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,090
Karma: 2701341
Join Date: Dec 2010
Device: Kindle 3
|
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. |
|
|
|
|
Enthusiast
|
|
|
|
#3 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 679
Karma: 1085478
Join Date: Mar 2009
Location: Bristol, England
Device: PRS-600, Acer 1825PT, Galaxy Tab, PRS-T1, HTC One X, TF700T
|
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>
__________________
Get 5GB of online storage for free from SugarSync. Click here for an additional 500MB to give you 5.5GB for free. Always have your stuff when you need it with @Dropbox. 2GB account is free! Click here Currently working on updating some of my Lovecraft work after receiving some corrections |
|
|
|
|
|
#4 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 679
Karma: 1085478
Join Date: Mar 2009
Location: Bristol, England
Device: PRS-600, Acer 1825PT, Galaxy Tab, PRS-T1, HTC One X, TF700T
|
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.
__________________
Get 5GB of online storage for free from SugarSync. Click here for an additional 500MB to give you 5.5GB for free. Always have your stuff when you need it with @Dropbox. 2GB account is free! Click here Currently working on updating some of my Lovecraft work after receiving some corrections |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
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 |