Notepad++ Regular Expression add up numbers

前端 未结 3 1244
一个人的身影
一个人的身影 2020-12-11 04:22

How do I sum or add a certain value to all those numbers? For example my goal is to increase all those numbers inside the \"\" with 100 but achieving that has been problemat

3条回答
  •  粉色の甜心
    2020-12-11 05:01

    I'm not really familiar with notepad++ but for an algorithm, supposing you have a number abcd = a*1000 +b*100 + c*10 + d, then so long as b is in [0,8] you can just replace b by b+1. As for when b = 9 then you need to replace b with 0 and replace a with a+1 (and if a = 9 then you'd replace a by 10).

    Noting this, you could then, for three and four digit numbers, say, apply the following regexes:

    \([1-9]+\)0\([0-9]{2}\) -> \1 1\2, 
    \([1-9]+\)1\([0,9]{2}\) -> \1 2\2, 
    ... -> , 
    \([1-9]+\)8\([0-9]{2}\) -> \1 9\2, 
    

    and so on ... Noting that you also have to consider any a=9, b=9 integers, and larger integers; this suggests some sort of iteration with if statements covering the cases where the coefficients of 10^x (x>=2) are equal to 9. When you start actually coding this (or doing it by hand) you will begin to realize that doing this with a pure regex approach is going to be painful.

提交回复
热议问题