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, 01: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,828
Karma: 908606
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, 01: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,828
Karma: 908606
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, 01: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: 64,784
Karma: 42802463
Join Date: Nov 2006
Location: UK
Device: Kindle Voyage, iPad Mini, iPhone 4, MS Surface Pro, N7
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 online now   Reply With Quote
Old 03-03-2010, 01: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,828
Karma: 908606
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, 01: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: 64,784
Karma: 42802463
Join Date: Nov 2006
Location: UK
Device: Kindle Voyage, iPad Mini, iPhone 4, MS Surface Pro, N7
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 online now   Reply With Quote
Old 03-03-2010, 01: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,978
Karma: 350515
Join Date: Feb 2008
Device: Sony Reader PRS 505
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, 01: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: 64,784
Karma: 42802463
Join Date: Nov 2006
Location: UK
Device: Kindle Voyage, iPad Mini, iPhone 4, MS Surface Pro, N7
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 online now   Reply With Quote
Old 03-03-2010, 01: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,978
Karma: 350515
Join Date: Feb 2008
Device: Sony Reader PRS 505
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, 01: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,978
Karma: 350515
Join Date: Feb 2008
Device: Sony Reader PRS 505
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, 01: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: 64,784
Karma: 42802463
Join Date: Nov 2006
Location: UK
Device: Kindle Voyage, iPad Mini, iPhone 4, MS Surface Pro, N7
No, I realised after I'd written it that I'd missed out the parentheses. A "senior moment" on my part.
HarryT is online now   Reply With Quote
Old 03-03-2010, 01: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,828
Karma: 908606
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, 05:34 AM   #12
gwynevans
Wizard
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,343
Karma: 1065246
Join Date: Nov 2007
Location: UK
Device: Sony 505 (retired), iPad2, iPhone 3GS & Nexus 7 3G
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, 10: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,828
Karma: 908606
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, 11: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,188
Karma: 727236
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, 04: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,828
Karma: 908606
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 06:51 AM
using wildcards for conversion ? Riiyachan Calibre 7 04-20-2010 11:16 PM
Help with a regex A.T.E. Calibre 1 04-05-2010 08:50 AM
wildcards in sigil bobcdy Sigil 2 12-18-2009 11:19 PM
Regex help... Bobthebass Workshop 6 04-26-2009 04:54 PM


All times are GMT -4. The time now is 03:14 PM.


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