Notepad++ Find/Replace number with Increment Value

前端 未结 2 626
情歌与酒
情歌与酒 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.

    0 讨论(0)
  • 2020-11-27 23:31

    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. I installed notepad++ 6.6.9 and now the Python menu tab shows up under plugins.

    0 讨论(0)
提交回复
热议问题