2

Say I have a regex of /\n(\d)+/.

Let's say I test it against some random text:

aaaaaaaaaa
5aaaaaaaaa
4707aaaaaa
aaaaaaaaaa
923aaaaaaa

Is there a way I can get the number of times \d was repeated for each match?

I ask this because I'm using regex to do a find and replace on Notepad++ and was hoping I could achieve this end-result:

aaaaaaaaaa
Xaaaaaaaaa
XXXXaaaaaa
aaaaaaaaaa
XXXaaaaaaa
mozicid
  • 55
  • 3

1 Answers1

3

If you want to match each digit at ^ start of line, the \G anchor can be used to chain matches. It matches at start of the string or where the previous match ended.

(?:\G|^)\d

Replace with

X

See this demo at regex101

bobble bubble
  • 16,888
  • 3
  • 27
  • 46