04-16-2013, 01:15 AM | #1 |
Enthusiast
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> 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> |
04-16-2013, 10:37 AM | #2 |
A Hairy Wizard
Posts: 3,186
Karma: 18843349
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/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*... |
Advert | |
|
04-16-2013, 11:47 AM | #3 |
Groupie
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 Last edited by mzmm; 04-16-2013 at 06:19 PM. Reason: malfunction |
04-16-2013, 02:21 PM | #4 | |
Wizard
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>
Code:
<div id="\1"><p\2><a href="\3"\4>\5<p\2><a href="\3">Return to Text</a></p></div>
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:
|
|
04-16-2013, 03:43 PM | #5 |
Enthusiast
Posts: 30
Karma: 502132
Join Date: May 2011
Device: Kindle3
|
Wow thank you so much guys - I am off to play!
|
Advert | |
|
|
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 |