View Single Post
Old 11-30-2011, 06:22 PM   #1
ElMiko
Addict
ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.
 
ElMiko's Avatar
 
Posts: 320
Karma: 56788
Join Date: Jun 2011
Device: Kindle
Replacing code without replacing text?

So I've now run into this problem twice. Hopefully, the reg-ex wizards among you will have a head-slappingly simple solution to my problem.

First Case
Every new paragraph is formatted as:
Code:
<p class="calibre2"><span class="none">A Bunch of Text</span></p>
I want to change the "p class" to "calibre5" for Chapter headings only, which are currently formatted like this (1., 2., 3., ..., 21., 22., etc):
Code:
<p class="calibre2"><span class="none">1.</span></p>
Finding all the instances with reg-ex is easy enough by searching for:
Code:
<p class="calibre2"><span class="none">[0-9]+\.</span></p>
But that's as far as I can get. Replacing the above with:
Code:
<p class="calibre5"><span class="none">[0-9]+\.</span></p>
changes the number to "[0-9]+\."!

Second Case
In another book, there are random paragraph breaks mid-sentence.
My solution to that would be to find all the new paragraphs that begin with a lower-case letter, and replace all the code between it and the previous paragraph. Again, finding the instances via reg-ex proved pretty intuitive:
Code:
</p>[\s]+<p class="calibre2">[a-z]
But again, i just can't figure out how to alter the code (in this case replacing it with a blank space) without altering the first letter of the first word in that paragraph.

Looking over what I've written, I am humbled by how utterly inarticulate this all sounds, but if someone understands my gibberish, I'd be most grateful for any light you could shine on my problem.

Last edited by ElMiko; 11-30-2011 at 06:40 PM.
ElMiko is offline   Reply With Quote