03-28-2021, 08:01 AM | #1 |
Groupie
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. |
03-28-2021, 09:04 AM | #2 | |
Zealot
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
|
Quote:
Hope someone develops a similar plug-in, or this feature will be also added to Sigil |
|
Advert | |
|
03-28-2021, 09:33 AM | #3 |
Groupie
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 )
|
04-01-2021, 05:41 PM | #4 | |
Grand Sorcerer
Posts: 5,651
Karma: 23456789
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): return str(len(match.group())) If your text contains AAA and AAAA, they should be replaced with 3 and 4. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Repeated Conversion | Kay Hemlock Brown | Conversion | 24 | 08-01-2020 07:17 PM |
Repeated Email Notifications | Mieeka | Feedback | 0 | 08-19-2019 06:45 PM |
Repeated crash | JustinThought | Sigil | 29 | 11-29-2017 07:17 AM |
Repeated contents in The Economist | Steven630 | Recipes | 5 | 06-21-2012 10:35 PM |
PRS-350 Repeated syncing | Jeanw | Sony Reader | 9 | 04-09-2012 05:28 PM |