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

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 09-16-2010, 01:11 PM   #1
potestus
Enthusiast
potestus began at the beginning.
 
Posts: 27
Karma: 10
Join Date: Jul 2010
Device: sony prs-600
REGEX find and replace help please

I have code that looks like:
<p class="calibre1">69</p> Where 69 is a chapter number
and I want them all to be like:

<h3>Chapter 69</h3>

obviously there are lots of <p class="calibre1">

Wild card <p class="calibre1">??< can find all the chapters but I have no way of resolving ?? to the chapter number.

I understand that REGEX could do this... any chance of a clue here - It may also help me to understand the concept.

Thanks in anticipation.
potestus is offline   Reply With Quote
Old 09-16-2010, 01:58 PM   #2
charleski
Wizard
charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1281258
Join Date: Sep 2009
Device: PRS-505
Find:
<p class="calibre1">(\d+)</p>
Replace:
<h3>Chapter \1</h3>
charleski is offline   Reply With Quote
Advert
Old 09-16-2010, 02:00 PM   #3
Perkin
Guru
Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.
 
Perkin's Avatar
 
Posts: 655
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
Try

serach
Quote:
<p class="calibre1">([0-9]+)</p>
replace
Quote:
<h3>Chapter \1</h3>
Regular expression + minimal matching
Edit: Doh` Too slow
Perkin is offline   Reply With Quote
Old 09-16-2010, 05:20 PM   #4
potestus
Enthusiast
potestus began at the beginning.
 
Posts: 27
Karma: 10
Join Date: Jul 2010
Device: sony prs-600
Thanks both..
The worked fine.

I guess the (\d+) or ([0-0]+) stores the numbers (how many? all until </p>?)

an \1 recalls them (the first set I suppose)? If I had more than one they woould be \2..\3 etc..

anyway it works much thanks.

anyway it worked
potestus is offline   Reply With Quote
Old 09-16-2010, 06:28 PM   #5
Perkin
Guru
Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.
 
Perkin's Avatar
 
Posts: 655
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
\d means a digit
[0-9] means any character 0,1,2,3,4,5,6,7,8,9
the + means match as many as possible
the brackets mean store this as a set
as this was surrounded by the<p> and </p> then we mean only line that start <p>
have only digits (no other characters/symbols etc.) and then finishes with </p>


We replace the whole section (including the <p> and </p>) with the <h3>Chapter
and then stored set (as you said), then finishes it of closing the <h3>.

It's worth reading up and trying to understand, as regex's make some thing a lot easier, (such as what you wanted) but as powerful as they can be, they can cause undesired results unless you know what your doing, so when starting to use regex's save often and if needed, quit out and re-load.
Perkin is offline   Reply With Quote
Advert
Old 09-16-2010, 06:29 PM   #6
PatNY
Zennist
PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.
 
PatNY's Avatar
 
Posts: 1,022
Karma: 47809468
Join Date: Jul 2010
Device: iPod Touch, Sony PRS-350, Nook HD+ & HD
I have a very similar question. I saw this thread so I thought I would just tack my question on to this.

If I want to replace a set of tags with another set, but the text in between the tags varies from instance to instance, with no definable pattern, and there are a hundred instances, how do I do that?

For example, I want to replace ...

<p class="calibre1">xyz text</p>

with ...

<blockquote class="calibre20">xyz text</blockquote>


I tried a wildcard search and was able to locate the first expression but wasn't able to figure out how to retain the text in between the tags when the tags were replaced.

Can someone help?
PatNY is offline   Reply With Quote
Old 09-16-2010, 07:22 PM   #7
pietvo
Reader
pietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notespietvo can name that song in three notes
 
pietvo's Avatar
 
Posts: 519
Karma: 24612
Join Date: Aug 2009
Location: Utrecht, NL
Device: Kobo Aura 2, iPhone, iPad
Put () around the part that you want to retain, then in the replacement use \1 to get it. If there are more () the the search expression you can use \1, \2, etc, just in order of the ().
pietvo is offline   Reply With Quote
Old 09-16-2010, 11:10 PM   #8
PatNY
Zennist
PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.PatNY ought to be getting tired of karma fortunes by now.
 
PatNY's Avatar
 
Posts: 1,022
Karma: 47809468
Join Date: Jul 2010
Device: iPod Touch, Sony PRS-350, Nook HD+ & HD
pietvo, thanks! Worked well.
PatNY is offline   Reply With Quote
Old 09-17-2010, 07:02 AM   #9
potestus
Enthusiast
potestus began at the beginning.
 
Posts: 27
Karma: 10
Join Date: Jul 2010
Device: sony prs-600
Thanks to all.
It has helped lots.

I now see the light.
potestus is offline   Reply With Quote
Old 09-17-2010, 10:22 AM   #10
charleski
Wizard
charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1281258
Join Date: Sep 2009
Device: PRS-505
The most important thing is always to make sure that you have 'minimal matching' checked, otherwise bad things can happen.
charleski is offline   Reply With Quote
Old 09-18-2010, 05:25 AM   #11
potestus
Enthusiast
potestus began at the beginning.
 
Posts: 27
Karma: 10
Join Date: Jul 2010
Device: sony prs-600
OK
I have
<h3 id="heading_id_2">Chapter 1</h3>

<p class="MsoNormal3"><span class="calibre62">one two three</span></p>

and I want <h3 id="heading_id_2">Chapter 1 - one two tree</h3>

I can get the 1 with \d but how do I pick up one two three the length and number of words here is variable

I tried \w+ to no avail?

Thanks in anticipation
potestus is offline   Reply With Quote
Old 09-18-2010, 06:03 AM   #12
potestus
Enthusiast
potestus began at the beginning.
 
Posts: 27
Karma: 10
Join Date: Jul 2010
Device: sony prs-600
I got it..

FIND
<h3 id="heading_id_(\d+)">Chapter (\d)</h3>

<p class="MsoNormal(\d+)"><span class="calibre(\d+)">(.+)</span></p>

Replace

<h3>Chapter \2 - \5</h3>

works OK.

after a cup of coffee

Last edited by potestus; 09-18-2010 at 07:29 AM.
potestus is offline   Reply With Quote
Old 09-18-2010, 11:13 AM   #13
Perkin
Guru
Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.Perkin calls his or her ebook reader Vera.
 
Perkin's Avatar
 
Posts: 655
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
potestus, where you have in the find string, Chapter (\d), be aware that that will only do Chapter 1-9, any double digit chapters will not be done, change it to (\d+) as you have the others to do multiple digits.
Perkin is offline   Reply With Quote
Old 09-18-2010, 04:14 PM   #14
potestus
Enthusiast
potestus began at the beginning.
 
Posts: 27
Karma: 10
Join Date: Jul 2010
Device: sony prs-600
Thanks,
yes I got that in my moment of light.

Then I opened up and found chapters up to 25.

may thanks.
potestus 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
Help with Word - Find & Replace Big Kev Workshop 3 09-21-2010 06:51 PM
find and replace, epub ampsonic Reading and Management 3 03-02-2010 03:20 AM
Find/Replace with regular expression hydrolith Sigil 6 03-01-2010 08:42 PM
Crashes on find / replace all mr ploppy Sigil 1 02-03-2010 12:35 PM
Using Find/Replace with BD Otter Sony Reader 7 02-28-2009 01:49 PM


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


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