[英]Notepad++ Regex + python script (addition in the replace)
I got quite the same problem of this guy " Notepad++ Regular Expression add up numbers " i don't know python (shame on me maybe). 我遇到了与这个人完全相同的问题“ Notepad ++正则表达式加数字 ”,我不知道python(也许让我感到羞耻)。 I got an array : 我有一个数组:
$_ArrFinal = array("A"=>1, "B" =>2, "C" => 3, "D" => 4, "E"=>4, "F" => "5",...)
I have simplify it but i need to increment all the value above 4 in this array by 1. So i did this like in the answer, but sadly it doesn't seems to work : 我已经简化了它,但是我需要将此数组中所有高于4的值加1。所以我像在答案中那样做,但是可惜它似乎不起作用:
def calculate(match):
return '=>%s)' %(match.group(1)+1)
editor.rereplace('=>([5-9]|[1-9]\d{1,})', calculate)
Any suggestion ? 有什么建议吗?
It seems that the default Python Script installation is not working well. 似乎默认的Python Script安装效果不佳。 This is what has just worked for me: 这就是刚刚为我工作的东西:
Code: 码:
def calculate(match):
return '%s%s'%(match.group(1), str(int(match.group(2))+1))
editor.rereplace(r'(=>\s*"?)(\d+)', calculate)
Then, just evoke this 'increment_numbers' script. 然后,只需调用此“ increment_numbers”脚本。
See the regex demo . 参见regex演示 。 The expression matches: 表达式匹配:
(=>\\s*"?)
- Group 1, =>
followed with zero or more whitespace symbols ( \\s*
) followed with an optional "
(as ?
matches one or zero preceding token) (=>\\s*"?)
-组1, =>
后跟零个或多个空格符号( \\s*
),后跟一个可选的"
(因为?
匹配一个或零个在前标记) (\\d+)
- Group 2, one or more digits (\\d+)
-第2组,一个或多个数字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.