View Single Post
Old 06-22-2010, 08:43 PM   #9
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 698
Karma: 150000
Join Date: Feb 2010
Device: none
Quote:
Originally Posted by Kivgaen View Post
I don't understand what you are saying... if My chapter headings looked like this:

<p class="h1">1. The Other Minister</p>

<p class="h1">2. Spinner's End</p>

<p class="h1">3. Will and Won't</p>

etc...

Then I could do a global find and replace that would search for the first instance of <p class="h1">... and then grab all of the string between that and the closing </p> tag and plop it into the new <h1> tag?

If that's what you're saying, that's perfect...
Yes, that is what I'm saying exactly. You need to use a "regular expression" search which would look something like this in sigil:

Find what: <p class="h1">(.+)</p>

and it means roughly this: "find a string that starts with <p class="h1">, followed by one or more of any character [that's the .+ part], followed by </p>. The parenthesis means "remember the part of the string that's represented by .+ -- that is, the "one or more characters" between the <p class="h1"> and the </p>." In general, you could have more than one set of parentheses. The contents of the first set gets assigned to the temporary variable \1, the second set to \2, and so on.

You must also check the box "Minimal Matching" on the search dialog, and choose the "Regular expression" radio button, and the "down" button.

If you don't check "minimal matching" the search string will match as big a string as possible, which would be from the first <p class="h1"> to the very last <p/> in the file, which you don't want in this case!

If your head seems like it's ready to explode, don't worry. It probably won't. That's a normal reaction to the concept of regular expressions. You get used to it, supposedly.

OK, now the fun part. the "Replace With:" string looks like this:

<h1>\1</h1>

which means that the <p class="h1"> gets replaced by <h1>, the </p> gets replaced with </h1>, and the contents of variable \1 (i.e. the actual text of the header) gets put in between. Voila.

I strongly recommend you test your regular expression using just "find," not "replace," before you turn it loose. Sometimes that's the only way to be sure what a given regex will do.

check out Zelda_Pinwheel's excellent thread on this topic. Lots of great information. It is here:

https://www.mobileread.com/forums/showthread.php?t=75805

Phew, that's a long and detailed answer from someone who knows next to diddly about regex. If I've made a mess of things, I hope someone more knowledgeable (Y'all know who you are!) will come along and clean it up.
st_albert is offline   Reply With Quote