Community
    • Login

    Replace guid with guid from list randomly

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 590 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ali GaffoorA
      Ali Gaffoor
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Mark OlsonM
        Mark Olson
        last edited by

        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()
        
        1 Reply Last reply Reply Quote 3
        • Mark OlsonM Mark Olson referenced this topic on
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors