Getting the number of repetitions in a regular expression

Let's say that I have a regex /\n(\d)+/

.

Let's say I test it for random text:

aaaaaaaaaa
5aaaaaaaaa
4707aaaaaa
aaaaaaaaaa
923aaaaaaa

      

Is there a way to get the number of times \d

for each match?

I am asking this because I am using a regular expression for find and replace in Notepad ++ and I hope I can achieve this end result:

aaaaaaaaaa
Xaaaaaaaaa
XXXXaaaaaa
aaaaaaaaaa
XXXaaaaaaa

      

+2


source to share


1 answer


If you want to match each digit at the beginning of the ^

beginning of a string, anchor \G

can be used to chain matches. It matches the beginning of the line or ends the previous match.

(?:\G|^)\d

      

Replace



X

      

See this demo at regex101

+3


source







All Articles