03-13-2024, 05:16 PM | #1 |
Swepub
Posts: 23
Karma: 10
Join Date: Dec 2023
Device: iPad
|
REGEX delete
Completely new to this.
Is it possible to remove all <div ids and it's corresponding end <\div> like below that has the class "Basic-Text-Frame" using regex? <div id="_idContainer020" class="Basic-Text-Frame"> |
03-13-2024, 05:50 PM | #2 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
Uses Find and Replace in regex mode, or the TagMechanic plugin for even easier use.
See the Sigil Users Guide for more info. |
Advert | |
|
03-14-2024, 10:42 AM | #3 | |
Evangelist
Posts: 420
Karma: 2737916
Join Date: May 2013
Location: Ontario, Canada
Device: Kindle KB, Oasis, Pop_Os!, Jutoh, Kobo Forma
|
Quote:
<div.*?class="Basic-Text-Frame"> and replace with nothing. Check it out one-at-a-time at first to make sure it is doing what you want, before hitting Replace All. Then use the Mend and Prettify All HTML files tool to get rid of the </div> tag ends left behind. Also try the plugin KevinH mentions, and do spend some time with the manual and regex tutorials. Regex is powerful and can easily destroy a book. |
|
03-14-2024, 11:12 AM | #4 |
A Hairy Wizard
Posts: 3,225
Karma: 19000635
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
|
You can even do it with one regex...ASSUMING you do not have nested <div>s:
Code:
find: <div.*?class="Basic-Text-Frame">(.*?)</div> replace:\1 |
03-14-2024, 02:40 PM | #5 | |
Bibliophagist
Posts: 40,579
Karma: 157444380
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
Code:
<div id="_idContainer020" class="Basic-Text-Frame"> <div class="heading"> <div class="heading-contents"> <div class="title-block"> <div class="element-number-block"> </div> <div class="title-block"> <h1 class="title">Chapter 2</h1> </div> </div> </div> </div> </div> |
|
Advert | |
|
03-14-2024, 04:24 PM | #6 |
A Hairy Wizard
Posts: 3,225
Karma: 19000635
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
|
Yup. That’s why I said “assuming you don’t have nested divs!”
|
03-14-2024, 06:06 PM | #7 |
Bibliophagist
Posts: 40,579
Karma: 157444380
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
I noticed that you said that but I wanted to emphasize it!
One of the first ePubs I got to try repairing was one where original editor used regex to make changes to some spans and the (unnecessary in my opinion), nested spans were munged which made the ePub almost unreadable. The original was bad enough before the edit with massive dropcaps which after the edit applied to the entire paragraph. |
03-16-2024, 07:48 AM | #8 |
Swepub
Posts: 23
Karma: 10
Join Date: Dec 2023
Device: iPad
|
Thanks a lot for great support.
TagMechanic did the trick... |
Tags |
regex |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
pdf regex question - regex that wraps to a new line | flyash | Conversion | 1 | 09-05-2021 10:00 AM |
Predefined regex for Regex-function | sherman | Editor | 3 | 01-19-2020 06:32 AM |
Q: Regex Find and Replace delete surrounding tags | hidden.platypus | Editor | 14 | 06-17-2015 12:16 AM |
python regex: delete text in preprocessing | sws | Recipes | 0 | 01-11-2013 10:01 AM |
Delete files in PC not equal to delete in Sony reader 505 | sheilalayoli | Sony Reader | 5 | 07-12-2009 04:13 PM |