Skip to content

Replace text with random values

This cannot be done with normal regular-expression replacement in Notepad++. The best way to do it in Notepad++ is with the Pythonscript plugin.

Starting in v7.8.1, Python Script is available using Plugins Admin from inside Notepad++, and you no longer need to install it manually as described in this Guide: How to install the PythonScript plugin on Notepad++.

Create a script from Notepad++ main menu (Plugins >> PythonScript >> New Script) using the code below and save the file (e.g.

import re
import random
import hashlib

def calculate(match):
    # copy match
    IdFound =
    # make sure passing an encoded string
    IdNew = int(hashlib.sha256(IdFound.encode('utf-8')).hexdigest(), 16) % 10**9
    # format return string
    return '"Id": "' + str(IdNew) + '",'

editor.rereplace(r'"Id": "[A-Za-z0-9]+",', calculate)

Let's assume the following JSON records are to be processed (note: the first and last ID are the same).

    "Order ID": 4984,
    "Parts group": "INTERIO",
    "Id": "3K2kVk023",
    "Order description": "justo. Nullam"
    "Order ID": 1925,
    "Parts group": "ELECTRA",
    "Id": "3L2kWk024",
    "Order description": "imperdiet"
    "Order ID": 8651,
    "Parts group": "INTERIO",
    "Id": "3K2kVk023",
    "Order description": "eu pede mollis"
  • Open the file you want to edit.
  • Run the script (Plugins >> PythonScript >> Scripts >> replace-random)