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 03-03-2010, 12:21 PM   #1
zelda_pinwheel
zeldinha zippy zeldissima
zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.
 
zelda_pinwheel's Avatar
 
Posts: 27,827
Karma: 921169
Join Date: Dec 2007
Location: Paris, France
Device: eb1150 & is that a nook in her pocket, or she just happy to see you?
More fun with regex / wildcards

I'm trying to automate a find and replace routine to change chapter numbers from paragraphs to headings. in other words, currently, they look like this : <p>1</p> and i want them to look like this : <h3>1</h3>

i first tried to do this with wildcards and i have no troubles finding the numbers, but unfortunately if i put <h3>?</h3> in the "replace" box, it replaces the number with "?". not helpful.

so now i'm trying regex search. i looked on the regex page here to find the code : http://doc.trolltech.com/4.6/qregexp.html#introduction

i should say, i know nothing about regex, but i'm trying to learn a bit.

this expression <p>[0-9]{1,3}</p> finds what i want, but when i replace, i have the same problem as with the wildcards...

can someone tell me, what is the regex (or wildcard !) code for "don't touch the stuff in the middle, change only the tags" ??? there must be a way to do this !
zelda_pinwheel is offline   Reply With Quote
Old 03-03-2010, 12:24 PM   #2
zelda_pinwheel
zeldinha zippy zeldissima
zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.
 
zelda_pinwheel's Avatar
 
Posts: 27,827
Karma: 921169
Join Date: Dec 2007
Location: Paris, France
Device: eb1150 & is that a nook in her pocket, or she just happy to see you?
oh, also, if anyone has a good (simple) tutorial for regex, i am interested !
zelda_pinwheel is offline   Reply With Quote
Old 03-03-2010, 12:29 PM   #3
HarryT
eBook Enthusiast
HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.
 
HarryT's Avatar
 
Posts: 85,544
Karma: 93383043
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
In most regex implementations, the "matches" for expressions are represented in the "replace" string by "\1", "\2", etc, so to replace:

<p>nnn<p>

by

<h3>nnn</h3>

you'd use a search string of:

<p>[0-9]*</p>

and a replace string of:

<h3>\1</h3>

where the "\1" will contain whatever was matched by the "[0-9]*".
HarryT is offline   Reply With Quote
Old 03-03-2010, 12:31 PM   #4
zelda_pinwheel
zeldinha zippy zeldissima
zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.
 
zelda_pinwheel's Avatar
 
Posts: 27,827
Karma: 921169
Join Date: Dec 2007
Location: Paris, France
Device: eb1150 & is that a nook in her pocket, or she just happy to see you?
Quote:
Originally Posted by HarryT View Post
In most regex implementations, the "matches" for expressions are represented in the "replace" string by "\1", "\2", etc, so to replace:

<p>nnn<p>

by

<h3>nnn</h3>

you'd use a search string of:

<p>[0-9]*</p>

and a replace string of:

<h3>\1</h3>

where the "\1" will contain whatever was matched by the "[0-9]*".
no joy. i tried putting "<h3>\1</h3>" in the replace box and it put \1 in place of my chapter number.
zelda_pinwheel is offline   Reply With Quote
Old 03-03-2010, 12:38 PM   #5
HarryT
eBook Enthusiast
HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.
 
HarryT's Avatar
 
Posts: 85,544
Karma: 93383043
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
Try using a search string of:

<p>([0-9]*)</p>

and a replace string of:

<h3>\1</h3>

ie, with parentheses around the "search string" for the numbers.
HarryT is offline   Reply With Quote
Old 03-03-2010, 12:41 PM   #6
Valloric
Created Sigil, FlightCrew
Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.
 
Valloric's Avatar
 
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
Quote:
Originally Posted by HarryT View Post
In most regex implementations, the "matches" for expressions are represented in the "replace" string by "\1", "\2", etc, so to replace:

<p>nnn<p>

by

<h3>nnn</h3>

you'd use a search string of:

<p>[0-9]*</p>

and a replace string of:

<h3>\1</h3>

where the "\1" will contain whatever was matched by the "[0-9]*".
Harry, I don't know what regex flavor you are using, but all the engines that I know of require parentheses for capture groups.

So like this:

Code:
<p>([0-9]*)</p>
And then:

Code:
<h3>\1</h3>
For what Zelda wants, I'd use this:

Code:
<p>(\d+)</p>
With this:

Code:
<h3>\1</h3>
Valloric is offline   Reply With Quote
Old 03-03-2010, 12:43 PM   #7
HarryT
eBook Enthusiast
HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.
 
HarryT's Avatar
 
Posts: 85,544
Karma: 93383043
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
Quote:
Originally Posted by Valloric View Post
Harry, I don't know what regex flavor you are using, but all the engines that I know of require parentheses for capture groups.
I know. See my previous post!
HarryT is offline   Reply With Quote
Old 03-03-2010, 12:44 PM   #8
Valloric
Created Sigil, FlightCrew
Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.
 
Valloric's Avatar
 
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
A good regex info site is http://www.regular-expressions.info/, and a great regex test site is Regexr. But do note that Regexr use the Perl notation for backreferences ("$#", e.g "$1", "$2"...) while Sigil uses the sed notation ("\#", e.g. "\1", "\2" ).
Valloric is offline   Reply With Quote
Old 03-03-2010, 12:45 PM   #9
Valloric
Created Sigil, FlightCrew
Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.Valloric ought to be getting tired of karma fortunes by now.
 
Valloric's Avatar
 
Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
Quote:
Originally Posted by HarryT View Post
I know. See my previous post!
That post was not there when I pressed the "Reply" button.
Valloric is offline   Reply With Quote
Old 03-03-2010, 12:46 PM   #10
HarryT
eBook Enthusiast
HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.HarryT ought to be getting tired of karma fortunes by now.
 
HarryT's Avatar
 
Posts: 85,544
Karma: 93383043
Join Date: Nov 2006
Location: UK
Device: Kindle Oasis 2, iPad Pro 10.5", iPhone 6
No, I realised after I'd written it that I'd missed out the parentheses. A "senior moment" on my part.
HarryT is offline   Reply With Quote
Old 03-03-2010, 12:48 PM   #11
zelda_pinwheel
zeldinha zippy zeldissima
zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.
 
zelda_pinwheel's Avatar
 
Posts: 27,827
Karma: 921169
Join Date: Dec 2007
Location: Paris, France
Device: eb1150 & is that a nook in her pocket, or she just happy to see you?
Quote:
Originally Posted by Valloric View Post
Harry, I don't know what regex flavor you are using, but all the engines that I know of require parentheses for capture groups.

So like this:

Code:
<p>([0-9]*)</p>
And then:

Code:
<h3>\1</h3>
For what Zelda wants, I'd use this:

Code:
<p>(\d+)</p>
With this:

Code:
<h3>\1</h3>
woohoo !! thanks valloric ! that worked perfectly. now when i'm done with all my other corrections i can copy all my html into previous sigil and add in my chapter break divs with a simple find and replace on <h3>. joy.

Quote:
Originally Posted by Valloric View Post
A good regex info site is http://www.regular-expressions.info/, and a great regex test site is Regexr. But do note that Regexr use the Perl notation for backreferences ("$#", e.g "$1", "$2"...) while Sigil uses the sed notation ("\#", e.g. "\1", "\2" ).
and thank you for that, too. i'm sure i'll have plenty of other expressions to find.
zelda_pinwheel is offline   Reply With Quote
Old 03-05-2010, 04:34 AM   #12
gwynevans
Wizzard
gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.
 
gwynevans's Avatar
 
Posts: 1,402
Karma: 2000000
Join Date: Nov 2007
Location: UK
Device: iPad 2, iPhone 6s, Kindle Voyage & Kindle PaperWhite
Quote:
Originally Posted by zelda_pinwheel View Post
i'm sure i'll have plenty of other expressions to find.
If you're running Windows, the Regex Coach (donationware) can be a useful utility to have around.
gwynevans is offline   Reply With Quote
Old 03-06-2010, 09:59 AM   #13
zelda_pinwheel
zeldinha zippy zeldissima
zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.
 
zelda_pinwheel's Avatar
 
Posts: 27,827
Karma: 921169
Join Date: Dec 2007
Location: Paris, France
Device: eb1150 & is that a nook in her pocket, or she just happy to see you?
Quote:
Originally Posted by gwynevans View Post
If you're running Windows, the Regex Coach (donationware) can be a useful utility to have around.
thank you ! i am indeed running windows, and a coach sounds like just what i need. i'll take a look.
zelda_pinwheel is offline   Reply With Quote
Old 03-18-2010, 10:13 PM   #14
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
Be sure to keep the 'minimal matching' box checked whenever you use regexes (unless you're sure you don't want it). Sigil's support for non-greedy matching is very admirable and makes all the difference.

If you're experimenting with more complex regexes it's always a good idea to address the problem in stages, and save the book under a new name after each replace operation so you can backtrack if something goes wrong.
charleski is offline   Reply With Quote
Old 03-28-2010, 03:51 PM   #15
zelda_pinwheel
zeldinha zippy zeldissima
zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.zelda_pinwheel ought to be getting tired of karma fortunes by now.
 
zelda_pinwheel's Avatar
 
Posts: 27,827
Karma: 921169
Join Date: Dec 2007
Location: Paris, France
Device: eb1150 & is that a nook in her pocket, or she just happy to see you?
thanks charleski, that is very sound advice, especially as i have already gotten myself into trouble doing a "replace all" with the wrong replacement... (and that was *before* i started to tackle regex searches).
zelda_pinwheel 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
What a regex is Worldwalker Calibre 20 05-10-2010 05:51 AM
using wildcards for conversion ? Riiyachan Calibre 7 04-20-2010 10:16 PM
Help with a regex A.T.E. Calibre 1 04-05-2010 07:50 AM
wildcards in sigil bobcdy Sigil 2 12-18-2009 10:19 PM
Regex help... Bobthebass Workshop 6 04-26-2009 03:54 PM


All times are GMT -4. The time now is 07:38 AM.


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