Hello, @genjua-khan, @peterjones and All,
@genjua-khan, in addition to the @peterjones’s solutions, may be the following Python script could interest you !
The explanations, regarding the use of this script, are included in comments
Note that the RULIC name of that script means Replace Using List In Clipboard !
'''
Based on : https://notepad-plus-plus.org/community/post/33977 ( Scott Sumner - August 2018 )
- Given a NEW tab, containing some lines, with the FORMAT : DELIMITER<Searched_Text>DELIMITER<Replacement_Text>, PASTED in the CLIPBOARD by a 'CTRL--C' action
- This script REPLACES any 'Searched_Text' ( of a 'CLIPBOARD line' ) with its CORRESPONDING 'Replacement_Text', in CURRENT file ( ACTIVE tab )
EXAMPLE :
Let's suppose that the THREE lines, below, are pasted in the CLIPBOARD :
!bar!foo
$Test$
:Bob:Ted
Then :
- Any 'bar' string will be changed by 'foo' in the present ACTIVE tab
- Any 'Test' string will be DELETED in the present ACTIVE tab
- Any 'Bob' first name will be changed by 'Ted' in the present ACTIVE tab
NOTES :
- IF the 'Replacement_Text', after the DELIMITER, is ABSENT, the 'Searched_Text' is then DELETED
- The DIFFERENT strings, to search for, are ALWAYS supposed to be LITERAL strings
- The DELIMITER may be DIFFERENT between TWO successive lines
- The list of the different SEARCHES [ and REPLACEMENTS ], with the DELIMITERS, must be PRESENT in the CLIPBOARD, RIGHT BEFORE running this script
'''
import re
def RULIC__main():
if not editor.canPaste(): return
cp = editor.getCurrentPos()
editor.setSelection(cp, cp) # cancel any ACTIVE selection(s)
doc_orig_len = editor.getTextLength()
editor.paste() # Paste so we can get easy access to the clipboard text
cp = editor.getCurrentPos() # The POSITION has moved because of the PASTE action
clipboard_lines_list = editor.getTextRange(cp - editor.getTextLength() + doc_orig_len, cp).splitlines()
editor.undo() # Revert the PASTE action, but sadly, this puts it in the undo buffer...so it can be redone
editor.beginUndoAction()
for line in clipboard_lines_list:
try: (search_text, replace_text) = line.rstrip('\n\r')[1:].split(line[0])
except (ValueError, IndexError): continue
editor.replace(search_text, replace_text) # DEFAULT search is SENSITIVE to case
#editor.replace(search_text, replace_text, re.I) # If an INSENSITIVE search is preferred
editor.endUndoAction()
RULIC__main()
Best Regards,
guy038