简体   繁体   English

Notepad ++查找/替换带有增量值的数字

[英]Notepad++ Find/Replace number with Increment Value

Is it possible in Notepad++ to find a number, then replace it with increment value? 是否可以在Notepad ++中找到一个数字,然后将其替换为增量值?

For example, find id number: regex \\((\\d+) 例如,找到ID号: regex \\((\\d+)

INSERT INTO `wp_make`(`id`, `name`, `slug`) VALUES (0,"audi","audi");
INSERT INTO `wp_make`(`id`, `name`, `slug`) VALUES (1,"BMW","bmw");
INSERT INTO `wp_make`(`id`, `name`, `slug`) VALUES (2,"Mercedes","mercedes");

replace with id + 31: how to? 用ID + 31替换: 如何?

INSERT INTO `wp_make`(`id`, `name`, `slug`) VALUES (31,"audi","audi");
INSERT INTO `wp_make`(`id`, `name`, `slug`) VALUES (32,"BMW","bmw");
INSERT INTO `wp_make`(`id`, `name`, `slug`) VALUES (33,"Mercedes","mercedes");

It is not possible with just a regex, but you can use a python script inside Notepad++. 仅使用正则表达式是不可能的,但是您可以在Notepad ++中使用python脚本。

Here are the steps: 步骤如下:

  • Install Python Script 1.0.8.0 安装Python脚本1.0.8.0
  • Go to the Plugins -> Python Script -> New Script 转到插件 -> Python脚本 -> 新脚本
  • Select the file name (say, "increment_numbers.py") 选择文件名(例如,“ increment_numbers.py”)
  • Place this script there: 将此脚本放在此处:

Code: 码:

def increment_after_openparen(match):
    return "({0}".format(str(int(match.group(1))+31))

editor.rereplace(r'\((\d+)', increment_after_openparen)

Then, just evoke this 'increment_numbers' script. 然后,只需调用此“ increment_numbers”脚本。

Addendum to the accepted answer. 已接受答案的附录。 Posting this as an answer due to insufficient rep 由于没有足够的代表而将其发布为答案

I noted that the newer version of Notepad ++ is not compatible with this python script. 我注意到,较新版本的Notepad ++与该python脚本不兼容。 I installed notepad++ 6.6.9 and now the Python menu tab shows up under plugins. 我安装了notepad ++ 6.6.9,现在Python菜单选项卡显示在插件下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM