Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 03-28-2021, 07:01 AM   #1
1v4n0
Groupie
1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.
 
Posts: 171
Karma: 40000
Join Date: Oct 2013
Device: kindle
Replace repeated item with the number of times it is repeated

Hello, is there a way to replace a character or a string, repeated continuously N times, with the number N?
Say, replace "AA" with "2", "AAA" with "3" and so on, in just one regular expression?


Thank you.
1v4n0 is offline   Reply With Quote
Old 03-28-2021, 08:04 AM   #2
The_book
Zealot
The_book began at the beginning.
 
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
Quote:
Originally Posted by 1v4n0 View Post
Hello, is there a way to replace a character or a string, repeated continuously N times, with the number N?
Say, replace "AA" with "2", "AAA" with "3" and so on, in just one regular expression?


Thank you.
calibre book-edit regex function replace. using python to do so.

Hope someone develops a similar plug-in, or this feature will be also added to Sigil
The_book is offline   Reply With Quote
Old 03-28-2021, 08:33 AM   #3
1v4n0
Groupie
1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.1v4n0 writes the songs that make the whole world sing.
 
Posts: 171
Karma: 40000
Join Date: Oct 2013
Device: kindle
Thank you. And what would the regex be? (just so I don't have to wade through the whole user manual )
1v4n0 is offline   Reply With Quote
Old 04-01-2021, 04:41 PM   #4
Doitsu
Grand Sorcerer
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: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by 1v4n0 View Post
Thank you. And what would the regex be? (just so I don't have to wade through the whole user manual )
In the Calibre Editor, press CTRL+F, select the regex function mode, click Create/edit, paste the following code into the editor,

Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    return str(len(match.group()))
give the function a name, e.g. CharLen and enter (A+) as the search expression.

If your text contains AAA and AAAA, they should be replaced with 3 and 4.
Doitsu is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeated Conversion Kay Hemlock Brown Conversion 24 08-01-2020 06:17 PM
Repeated Email Notifications Mieeka Feedback 0 08-19-2019 05:45 PM
Repeated crash JustinThought Sigil 29 11-29-2017 06:17 AM
Repeated contents in The Economist Steven630 Recipes 5 06-21-2012 09:35 PM
PRS-350 Repeated syncing Jeanw Sony Reader 9 04-09-2012 04:28 PM


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


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