Notepad++ RegEx replace with Zerofill

2020-04-26 02:05发布

问题:

I need to replace a list like this:

105164 25
105164 26
105164 29
105496 1
105496 2

To

105164_0025
105164_0026
105164_0029
105496_0001
105496_0002

Something like (\w)([0-9]+) to _$1 but how to do the left zero padding?

回答1:

[ ]([0-9]+) to _$1   --do your first replace
_([0-9])$ to _000$1
_([0-9][0-9])$ to _00$1
_([0-9][0-9][0-9])$ to _0$1

Kind of a cheat method but that's the only way I can think of.



回答2:

You can do in two passes:

first pass:
Find what: (\d+)$
Replace with: _0000$1

second pass:
Find what: _0*(\d{4})$
Replace with: _$1