|
|
#1 |
|
zeldinha zippy zeldissima
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 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 !
__________________
blog.ex-elibris.fr : les liseuses, les ebooks, nos lectures, la technologie… I don't want none of that mischief on my eels! - pdurrant since i would never want to disappoint wde and vr, we are thrilled to present the next exciting avatar in zelda's wardrobe, by vivaldirules himself. |
|
|
|
|
|
#2 |
|
zeldinha zippy zeldissima
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 !
__________________
blog.ex-elibris.fr : les liseuses, les ebooks, nos lectures, la technologie… I don't want none of that mischief on my eels! - pdurrant since i would never want to disappoint wde and vr, we are thrilled to present the next exciting avatar in zelda's wardrobe, by vivaldirules himself. |
|
|
|
|
Enthusiast
|
|
|
|
#3 |
|
eBook Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 55,160
Karma: 27556397
Join Date: Nov 2006
Location: UK
Device: Kindle Touch, PW, Fire HD, iPad 3, iPhone 4, Samsung Tab 2 7 + More
|
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 Currently proofreading The Poison Belt, by Sir Arthur Conan Doyle. |
|
|
|
|
|
#4 | |
|
zeldinha zippy zeldissima
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
__________________
blog.ex-elibris.fr : les liseuses, les ebooks, nos lectures, la technologie… I don't want none of that mischief on my eels! - pdurrant since i would never want to disappoint wde and vr, we are thrilled to present the next exciting avatar in zelda's wardrobe, by vivaldirules himself. |
|
|
|
|
|
|
#5 |
|
eBook Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 55,160
Karma: 27556397
Join Date: Nov 2006
Location: UK
Device: Kindle Touch, PW, Fire HD, iPad 3, iPhone 4, Samsung Tab 2 7 + More
|
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.
__________________
Harry Currently proofreading The Poison Belt, by Sir Arthur Conan Doyle. |
|
|
|
|
|
#6 | |
|
Created Sigil, FlightCrew
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,975
Karma: 348069
Join Date: Feb 2008
Device: Sony Reader PRS 505
|
Quote:
So like this: Code:
<p>([0-9]*)</p> Code:
<h3>\1</h3> Code:
<p>(\d+)</p> Code:
<h3>\1</h3> |
|
|
|
|
|
|
#7 |
|
eBook Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 55,160
Karma: 27556397
Join Date: Nov 2006
Location: UK
Device: Kindle Touch, PW, Fire HD, iPad 3, iPhone 4, Samsung Tab 2 7 + More
|
I know. See my previous post!
__________________
Harry Currently proofreading The Poison Belt, by Sir Arthur Conan Doyle. |
|
|
|
|
|
#8 |
|
Created Sigil, FlightCrew
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,975
Karma: 348069
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" ).
|
|
|
|
|
|
#9 |
|
Created Sigil, FlightCrew
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,975
Karma: 348069
Join Date: Feb 2008
Device: Sony Reader PRS 505
|
That post was not there when I pressed the "Reply" button.
|
|
|
|
|
|
#10 |
|
eBook Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 55,160
Karma: 27556397
Join Date: Nov 2006
Location: UK
Device: Kindle Touch, PW, Fire HD, iPad 3, iPhone 4, Samsung Tab 2 7 + More
|
No, I realised after I'd written it that I'd missed out the parentheses. A "senior moment" on my part.
__________________
Harry Currently proofreading The Poison Belt, by Sir Arthur Conan Doyle. |
|
|
|
|
|
#11 | ||
|
zeldinha zippy zeldissima
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
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:
i'm sure i'll have plenty of other expressions to find.
__________________
blog.ex-elibris.fr : les liseuses, les ebooks, nos lectures, la technologie… I don't want none of that mischief on my eels! - pdurrant since i would never want to disappoint wde and vr, we are thrilled to present the next exciting avatar in zelda's wardrobe, by vivaldirules himself. |
||
|
|
|
|
|
#12 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,344
Karma: 1065246
Join Date: Nov 2007
Location: UK
Device: Sony 505 (retired), iPad2, iPhone 3GS & Nexus 7 3G
|
If you're running Windows, the Regex Coach (donationware) can be a useful utility to have around.
|
|
|
|
|
|
#13 | |
|
zeldinha zippy zeldissima
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
i'll take a look.
__________________
blog.ex-elibris.fr : les liseuses, les ebooks, nos lectures, la technologie… I don't want none of that mischief on my eels! - pdurrant since i would never want to disappoint wde and vr, we are thrilled to present the next exciting avatar in zelda's wardrobe, by vivaldirules himself. |
|
|
|
|
|
|
#14 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,181
Karma: 539735
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. |
|
|
|
|
|
#15 |
|
zeldinha zippy zeldissima
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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).
__________________
blog.ex-elibris.fr : les liseuses, les ebooks, nos lectures, la technologie… I don't want none of that mischief on my eels! - pdurrant since i would never want to disappoint wde and vr, we are thrilled to present the next exciting avatar in zelda's wardrobe, by vivaldirules himself. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
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 |