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 07-31-2012, 07:53 AM   #1
ElMiko
Addict
ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.
 
ElMiko's Avatar
 
Posts: 295
Karma: 56788
Join Date: Jun 2011
Device: Kindle
Backreferencing "or" expressions

I want to find all instances of quotation marks inside <i> tags
Code:
<i>“|”</i>
and then replace all so that the quotation marks are on the outside, but I'm coming up empty. Placing "|" in the replace field merely does a literal character replacement. And breaking up the search into four parentheticals, and trying to backreference them also didn't work. Obviously, this is an exceedingly straighforward search/replace action in two steps, but I'm wondering if there's a magic bullet out there that can get it done in a single step (that is, a single action that combines both searches and yields the desired replacement values).

I was using the following test string:

Code:
<p><i>“Hello, I love you,”</i> I said.</p>
<p><i>“Won't you tell me your name?”</i></p>
with the desired result of

Code:
<p><i>Hello, I love you,</i> I said.</p>
<p><i>Won't you tell me your name?</i></p>

Last edited by ElMiko; 07-31-2012 at 07:59 AM.
ElMiko is offline   Reply With Quote
Old 07-31-2012, 09:11 AM   #2
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 5,795
Karma: 4027751
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon
I'm not sure it works in Sigil's regex dialect, but this seems to work in vim:

Code:
%s/\(<i>\)\(“\)\|\(”\)\(<\/i>\)/\2\1\4\3/g
which could translate to:

search:
Code:
(<i>)(“)|(”)(</i>)
replace:
Code:
\2\1\4\3
Jellby is online now   Reply With Quote
Old 07-31-2012, 11:32 AM   #3
Serpentine
Evangelist
Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.Serpentine ought to be getting tired of karma fortunes by now.
 
Posts: 416
Karma: 1045911
Join Date: Sep 2011
Location: Cape Town, South Africa
Device: Kindle 3
Dont see why you're trying to do fancy stuff, given the very easy sample set, it might be worth just using the simplest case:
Code:
Find : <i\b[^<>]*>([^“]*)“([^”]+)”([^“”]*)</i>

Replace : \1“<i>\2</i>”\3
Just grep first to be safe, it will eat homework.
Serpentine is offline   Reply With Quote
Old 07-31-2012, 01:31 PM   #4
Jabby
Jr. - Junior Member
Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.Jabby ought to be getting tired of karma fortunes by now.
 
Posts: 560
Karma: 2000170
Join Date: Aug 2010
Location: East Texas
Device: Archos, Asus, HP, Lenovo, Nexus and Samsung tablets in 7,8 and 10"
Would't this work?
Find:
Code:
<i>“(.*?)”</i>
Replace:
Code:
"<i>\1</i>"
Regards - John
Jabby is offline   Reply With Quote
Old 07-31-2012, 05:42 PM   #5
mmat1
Det
mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.mmat1 ought to be getting tired of karma fortunes by now.
 
mmat1's Avatar
 
Posts: 914
Karma: 936586
Join Date: Jan 2012
Location: Zischebattem
Device: Acer Lumiread
Quote:
Originally Posted by Jabby View Post
Would't this work?
Of course this will work with the samples. As well as a non-regex-replace in two steps.

The interesting part of the question was how to backref something which is found with an "or-clause".
mmat1 is offline   Reply With Quote
Old 08-02-2012, 10:06 AM   #6
ElMiko
Addict
ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.ElMiko actually enjoys Vogon poetry.
 
ElMiko's Avatar
 
Posts: 295
Karma: 56788
Join Date: Jun 2011
Device: Kindle
PS - this is why I don't like giving sample sets.... because people try to match the sets instead of the premise. Indeed, the italic/quotation mark search is merely the scenario that inspired me to look for an answer to the "or" backreference question, but there is literally an infinitude of "or" searches.

Nevertheless, I do i appreciate the help you've all volunteered on the quotation mark issue.
ElMiko 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
KT "Ghost covers/files" again at 670 books, "stale" image entries in firmware VirgoGirl Kobo Reader 4 04-06-2012 02:10 PM
Feature Request: configurable space setting for "Insert blank line" in "Look & Feel" therealjoeblow Calibre 15 07-25-2011 03:14 PM
Sigil 024 and regular expressions on "all HTML files" WS64 Sigil 4 08-13-2010 07:33 PM


All times are GMT -4. The time now is 10:50 AM.


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