I think this script will do what you want
# encoding=utf-8 """https://community.notepad-plus-plus.org/topic/23149/find-and-replace-with-increments/4 This will start by matching text from `{` at the beginnig of a line to `}` or `},` at the beginning of a line Inside those groups, it will replace all "zone_#" or "zone #" with the value of the counter The counter will increment between `{...}` groups """ from Npp import * import re counter = 1 def replace_group(m): global counter out = re.sub(r'(?<=zone[ _])\d+', str(counter), m.group(0)) counter = counter + 1 return out console.clear() editor.beginUndoAction() editor.rereplace(r'(?s)^{\h*$.*?^},?\h*$', replace_group) editor.endUndoAction()The editor.rereplace line matches from { at the beginning of a line to } or }, at the beginning of a line. It then calls replace_group() on that match. The second function does the search-and-replace inside that group, looking for zone followed by either _ or space, followed by one or more digits, and replaces those digits with the current value of the counter. Every group of { to }, will increment the counter by one, so each chunk will get a unique number, but use the same number inside.
Assumptions:
That your example data isn’t missing leading spaces, because the regex assumes the { and }, are at the beginning of the line. That there aren’t any other { and }, at the beginning of lines embedded inside (so nicely indented and properly formulated json) That zone_1 and zone 1 within a single {…} block should all get the same counter value That you don’t have any zone_### inside your blocks that you don’t want changed (you didn’t show any, but…)