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

Go Back   MobileRead Forums > E-Book Formats > Workshop

Notices

Reply
 
Thread Tools Search this Thread
Old 04-16-2013, 01:15 AM   #1
lissie
Enthusiast
lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.
 
Posts: 30
Karma: 502132
Join Date: May 2011
Device: Kindle3
Struggling with regex over multiple lines

Okay I'm not the best with regex but I know this must be possible. I have a book with hundreds of footnotes. Some of the footnotes are a page long! I want to add a "return to text" hyperlink at the bottom of each footnote.

Each footnote will have one or many paragraphs. Some have images as well.

I want to go from this:
Code:
<div id="edn1">
<p class="someclass"><a href="#_ednref1" name="_edn1" title="">[1]</a>Footnote #1 and some words </p>
<p class="someclass">And another paragraph of footnote 2</p>
</div>
To this:
Code:
<div id="edn1">
<p class="someclass"><a href="#_ednref1" name="_edn1" title="">[1]</a>Footnote #1</p>
<p class="someclass">And another paragraph of footnote 1 but only sometimes</p>
<p class="someclass"><a href="#_ednref1">Return to Text</a></p>
</div>
I'm using notepad++ which AFAIK uses standard regex search/replace functions
lissie is offline   Reply With Quote
Old 04-16-2013, 10:37 AM   #2
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,092
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
in sigil you could use "\s*" in the find field to search for any amount of space including new paragraphs. Then use "\n" to insert a linefeed in the replace field.

I know that \n works in NP++ but I don't remember ever using \s*...
Turtle91 is offline   Reply With Quote
Advert
Old 04-16-2013, 11:47 AM   #3
mzmm
Groupie
mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.
 
mzmm's Avatar
 
Posts: 171
Karma: 86271
Join Date: Feb 2012
Device: iPad, Kindle Touch, Sony PRS-T1
i don't use notepad++ so can't verify, but i guess you'd want something like this:

Code:
find:
(<p class="someclass">)(<a href="[^"]+")(.*?)(</div>)

replace:
\1\2\3\1\2>Go Back</a></p>\4
there's probably an option to turn on 'dot matches new line' in the search/replace field which you should use. might have to play around with it to get it working properly but hope it's helpful

Last edited by mzmm; 04-16-2013 at 06:19 PM. Reason: malfunction
mzmm is offline   Reply With Quote
Old 04-16-2013, 02:21 PM   #4
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Ok I tested on your example, hopefully it works on others:

Search:

Code:
<div id="([^"]+)">\s*<p([^>]+)><a href="([^"]+)"([^>]+)>(.*)</div>
Replace:

Code:
<div id="\1"><p\2><a href="\3"\4>\5<p\2><a href="\3">Return to Text</a></p></div>
NOTE: I had a whole color coordinated post to try to explain it more in depth, but there were too many capture points and I thought it would be a little confusing. If you need a more in depth explanation, I would not mind breaking it down for you.

As a side note, I personally think that a "Return to Text" link is a little hideous (the original footnote should point right back to where you came from).

Quote:
Originally Posted by mzmm View Post
there's probably an option to turn on 'dot matches new line' in the search/replace field which you should use. might have to play around with it to get it working properly but hope it's helpful
Yes, put a checkbox in "dot matches newline", that will allow the red part to capture everything until the </div>.
Tex2002ans is offline   Reply With Quote
Old 04-16-2013, 03:43 PM   #5
lissie
Enthusiast
lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.lissie ought to be getting tired of karma fortunes by now.
 
Posts: 30
Karma: 502132
Join Date: May 2011
Device: Kindle3
Wow thank you so much guys - I am off to play!
lissie is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Struggling with RegEx phossler Sigil 10 01-13-2013 02:00 AM
Breaking Title Displays Across Multiple Lines register512 Devices 10 12-30-2012 10:27 PM
restricting regex to single lines of code? ElMiko Sigil 14 01-28-2012 04:39 PM
Replacing multiple tags over 2 lines kmckinley Sigil 7 09-03-2011 10:34 PM
Regex Question involving multiple . (periods) hanbalfrek Conversion 11 08-29-2011 05:06 PM


All times are GMT -4. The time now is 05:01 PM.


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