![]() |
#1 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 173
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. |
![]() |
![]() |
![]() |
#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 | |
|
![]() |
#3 |
Groupie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 173
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
![]() |
![]() |
![]() |
![]() |
#4 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,721
Karma: 24031401
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. |
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |