Replace guid with guid from list randomly
-
Good day.
would anyone know how to replace a guid with another guid from a list and do this randomly.
example : “d0ba703e-69d4-4253-9a8c-58668bce4aea” there are multiple of this guid in the file and i would like to replace it with the following in a random pattern:
a3ba621f-884c-4954-87e3-063014e927ff
b56483a2-3962-4d40-adc6-3f98cb4425c4
3b00ca11-db38-4d1d-b1e1-7ad008399919
540e5c95-4d79-4e70-8820-574b931c4a87
6b3fea3f-f5a4-402e-a65a-cc022d733ed4
e757d703-7e0f-49a5-8e11-0b79f2f1f39b
703d5a2f-3793-4e76-a7bf-d5b73231dfff -
The regex gurus on this forum might come up with some kind of crazy regex-based solution to this, but this is pretty easy to solve with PythonScript.
# requires PythonScript: https://github.com/bruderstein/PythonScript/releases # ref: https://community.notepad-plus-plus.org/topic/25388/replace-guid-with-guid-from-list-randomly import random import re from Npp import editor, notepad, MESSAGEBOXFLAGS def main(): thing_to_replace = notepad.prompt('Enter the text you want to replace', 'enter text to replace', '') if not thing_to_replace: return is_regex = notepad.messageBox( 'Is the thing you want to replace a regular expression?', 'regular expression?', MESSAGEBOXFLAGS.YESNO) == MESSAGEBOXFLAGS.RESULTYES if not is_regex: thing_to_replace = '(?-s)' + re.escape(thing_to_replace) replacements = notepad.prompt( 'Enter a list of replacements (one per line)', 'list of replacements', '') if not replacements: return replacement_list = replacements.strip().splitlines() def get_random_from_list(_): return random.choice(replacement_list) editor.rereplace(thing_to_replace, get_random_from_list) if __name__ == '__main__': main() -
M Mark Olson referenced this topic on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login