Notepad++ Find/Replace number with Increment Value

前端 未结 2 672
情歌与酒
情歌与酒 2020-11-27 22:49

Is it possible in Notepad++ to find a number, then replace it with increment value?

For example, find id number: regex \\((\\d+)

<
2条回答
  •  孤街浪徒
    2020-11-27 23:25

    It is not possible with just a regex, but you can use a python script inside Notepad++.

    Here are the steps:

    • Install Python Script 1.0.8.0
    • Go to the Plugins -> Python Script -> New Script
    • Select the file name (say, "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.

提交回复
热议问题