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 09-12-2018, 09:22 PM   #1
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: 1,696
Karma: 11766398
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 6/5/iPad 1,2 & Air/Surface Pro/Kindle PW
Regex for Marking Text?

Does anyone know of a way to restrict a find/replace to marked text....within the search parameter? I know you can manually mark the text with Ctrl + Shift + M, but I'm hoping to do it as part of a saved search group.

eg.

Step one:
find: <table(.*?)>(.*?)</table> and set as marked text

Step two:
find (within marked text): <p>(.*?)></p> and replace: \1

Step three:
Change the 'marked text' selector back to "All HTML Files"

Thanks,
Turtle91 is offline   Reply With Quote
Old 09-13-2018, 04:19 AM   #2
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,349
Karma: 14316543
Join Date: Dec 2010
Device: Kindle PW2
If it's usually only one section that you want to update, simply highlight it, right-click it and select Mark Selected Text from the context menu.

All Find & Replace actions will only be applied to that section.
Doitsu is offline   Reply With Quote
Advert
Old 09-13-2018, 12:20 PM   #3
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: 1,696
Karma: 11766398
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 6/5/iPad 1,2 & Air/Surface Pro/Kindle PW
Yes, I'm familiar with the manual method. In this particular instance I am trying to clean out all the <p> tags inside of a table....and there are over 200 tables If I can build it as part of a saved search group that would save a lot of highlighting and right-clicking.

My other option, of course, is to have a much more complex search, but I was worried about having too many saved groups (.*?)...isn't there a limit of like 5 or 6 within a given regex?
Turtle91 is offline   Reply With Quote
Old 09-13-2018, 01:23 PM   #4
Klecks
Enthusiast
Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.Klecks never is beset by a damp, drizzly November in his or her soul.
 
Klecks's Avatar
 
Posts: 33
Karma: 59154
Join Date: May 2010
Location: Stuttgart, Germany
Device: Kobo H2O, PocketBook Touch HD, Tolino Vision 4
I don't have a solution for a sigil regex, but if you want to try the calibre editor, you can use the function mode.
The function mode gives you the possibility of more advanced text processing.
It should be perfect for your problem:

Open your book with the calibre editor.
Choose one of the html-files on the left panel and click Ctrl+F.
Insert "<table[^>]*>.*?</table>" in the field "Find:"
Choose Mode "Regex-function" and click create/edit.


In the new window you will have the basic structure of a function.
In the upper field you can insert a name (maybe "clean_tables") and the the given basic function you should replace with:

Code:
import regex
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    return regex.sub(r'<p[^>]*>(.*?)</p>',r'\1',match.group())
Confirm with OK and you can use the new function.

Klecks
Attached Thumbnails
Click image for larger version

Name:	function_1.JPG
Views:	43
Size:	53.8 KB
ID:	166277   Click image for larger version

Name:	function_structure.JPG
Views:	44
Size:	84.7 KB
ID:	166278   Click image for larger version

Name:	function_clean_table.JPG
Views:	44
Size:	98.7 KB
ID:	166279   Click image for larger version

Name:	function_ready.JPG
Views:	39
Size:	55.4 KB
ID:	166280  
Klecks is offline   Reply With Quote
Old 09-13-2018, 03:15 PM   #5
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: 1,696
Karma: 11766398
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 6/5/iPad 1,2 & Air/Surface Pro/Kindle PW
Wow - that's awesome! I had played with regex functions a while back and knew they were powerful, but hadn't thought about them in a while. I guess that shows we can get stuck in our ruts and fail to think outside of the comfort box.

Thanks!
Turtle91 is offline   Reply With Quote
Advert
Old 09-13-2018, 03:47 PM   #6
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: 1,696
Karma: 11766398
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 6/5/iPad 1,2 & Air/Surface Pro/Kindle PW
I don't know the proprieties about sharing code between two open-source projects like Sigil & Calibre.

Is it a thing/possibility to implement the regex-functions capability within Sigil?
Turtle91 is offline   Reply With Quote
Old 09-13-2018, 06:14 PM   #7
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: 1,107
Karma: 6099999
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by Turtle91 View Post
Yes, I'm familiar with the manual method. In this particular instance I am trying to clean out all the <p> tags inside of a table....and there are over 200 tables If I can build it as part of a saved search group that would save a lot of highlighting and right-clicking.
I also have a set of 5 Saved Search Regexes I use to clean out Finereader table cruft:

Search: <td>\s+<p>([^<]+)</p>\s+</td>
Replace: <td>\1</td>

[...]

Search: <td colspan="([0-9]+)">\s+<p>([^<]+)</p>\s+</td>
Replace: <th colspan="\1">\2</th>

You could adapt something similar for your specific case.

Last edited by Tex2002ans; 09-13-2018 at 06:20 PM.
Tex2002ans is offline   Reply With Quote
Old 09-13-2018, 06:48 PM   #8
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 19,361
Karma: 99455064
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Turtle91 View Post
I don't know the proprieties about sharing code between two open-source projects like Sigil & Calibre.

Is it a thing/possibility to implement the regex-functions capability within Sigil?
I'm guessing a Sigil plugin could be worked up that would allow similar functionality. You're basically creating a library of small custom python routines (using predefined parameters) to alter text matched by a regexp.

Last edited by DiapDealer; 09-13-2018 at 07:03 PM.
DiapDealer is online now   Reply With Quote
Old 09-13-2018, 08:22 PM   #9
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: 1,696
Karma: 11766398
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 6/5/iPad 1,2 & Air/Surface Pro/Kindle PW
I've been a 'programmer' my whole life...not in any way professionally... basic/fortran/pascal/vba and wrote a little web app with Google Apps Script this week... which forced me to learn JS over the last couple of days. I haven't looked at python at all.

If it's OK with Kovid and the Calibre community I could peruse their code and give it my best shot at plug-in-ifying it???
Turtle91 is offline   Reply With Quote
Old 09-13-2018, 08:23 PM   #10
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: 1,696
Karma: 11766398
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 6/5/iPad 1,2 & Air/Surface Pro/Kindle PW
Quote:
Originally Posted by Tex2002ans View Post
I also have a set of 5 Saved Search Regexes I use to clean out Finereader table cruft:

Search: <td>\s+<p>([^<]+)</p>\s+</td>
Replace: <td>\1</td>

[...]

Search: <td colspan="([0-9]+)">\s+<p>([^<]+)</p>\s+</td>
Replace: <th colspan="\1">\2</th>

You could adapt something similar for your specific case.
Thanks Tex!
Turtle91 is offline   Reply With Quote
Old 09-13-2018, 10:11 PM   #11
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 19,361
Karma: 99455064
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Turtle91 View Post
If it's OK with Kovid and the Calibre community I could peruse their code and give it my best shot at plug-in-ifying it???
If you feel so moved, have it at!

Happy to offer some tips if you get snagged.
DiapDealer is online now   Reply With Quote
Old 09-14-2018, 04:41 AM   #12
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,349
Karma: 14316543
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Turtle91 View Post
I haven't looked at python at all.
IMHO, one of best Python crash courses is Al Sweigarts's Creative Commons licensed book Automate the Boring Stuff with Python, which is available online.

You also might want to check out the Beautiful Soup Python module, which is bundled with Sigil.

BTW, the last topic in the Sigil plugin development thread contains minimal code for a very simple plugin that boldens "the" in all HTML files.
Doitsu is offline   Reply With Quote
Old 09-14-2018, 11:11 AM   #13
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: 1,696
Karma: 11766398
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 6/5/iPad 1,2 & Air/Surface Pro/Kindle PW
Great - thanks!

That'll give me something to do while I'm sitting around waiting for Florence to get a move on...
Turtle91 is offline   Reply With Quote
Old 09-18-2018, 06:30 PM   #14
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: 1,696
Karma: 11766398
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 6/5/iPad 1,2 & Air/Surface Pro/Kindle PW
"I know kung-fu."


Que training montage to get my fingers familiar with what's in my brain...

Turtle91 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
Regex questions (body of text only?) rosshalde Sigil 3 10-23-2014 10:02 PM
Is there a way to remove text from Title with regex LadyKate Library Management 8 02-14-2014 05:12 PM
Is there RegEx to <span> ALL CAPS text? phossler Sigil 4 03-10-2013 03:43 PM
PRS-650 Text Marking gets awful slow with time on my PRS650 Leserli Sony Reader 29 08-13-2011 11:33 PM
Reading software with marking text nettomb Android Devices 9 10-01-2010 03:55 PM


All times are GMT -4. The time now is 08:00 AM.


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