我对这个家伙"Notepad++正则表达式累加数字“也有同样的问题,我不知道python (可能是我的耻辱)。我得到了一个数组:
$_ArrFinal = array("A"=>1, "B" =>2, "C" => 3, "D" => 4, "E"=>4, "F" => "5",...)我简化了它,但是我需要将这个数组中4以上的所有值增加1。
def calculate(match):
return '=>%s)' %(match.group(1)+1)
editor.rereplace('=>([5-9]|[1-9]\d{1,})', calculate)有什么建议吗?
发布于 2016-02-12 17:45:17
默认的Python脚本安装似乎不能正常工作。这就是刚刚对我起作用的:
代码:
def calculate(match):
return '%s%s'%(match.group(1), str(int(match.group(2))+1))
editor.rereplace(r'(=>\s*"?)(\d+)', calculate)然后,就会想起这个'increment_numbers‘脚本。
见regex演示。表达式匹配:
(=>\s*"?) -第1组,=>后面跟着零或多个空格符号(\s*),后面跟着可选的" (因为?匹配一个或零个前面的标记)(\d+) -第2组,一个或多个数字https://stackoverflow.com/questions/35366602
复制相似问题