2

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

For example, find id number: 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?

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");
Sevi
  • 863
  • 4
  • 15
  • 33

2 Answers2

8

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.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
1

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.

kerwei
  • 1,822
  • 1
  • 13
  • 22