Can I store/record regex replace operations then run them later?
barishamil last edited by
I want to save a replace operation like “(A?)(B?)” -> “AA$1BB$1” and play it later on demand
guy038 last edited by guy038
Hello, @barishamil, and All,
I’m afraid NOT :-(( I, personally, would like this valuable feature implemented in N++ !
Just make a request on GitHub at the address :
or search for a similar request and upvote for that one !
Of course, a trivial solution could be to store all your Search / Replacement couple of regexes in a specific file, containing your preferred S/R operations, in order to select them again when you would like to perform a specific an/or complicated S/R !
Meanwhile, you may be interested by a Python script, created by @claudia-frank, ten months ago !
Assuming that you previously set the multi-selections mechanism ( Settings > Preferences…> Editing > Multi-Editing Setings ), in your N++ configuration :
Do a FIRST selection of the regex which is to fill up, in the Find what: zone
Then, do a SECOND selection of the regex, which is to fill up, in the Replace with: zone
Run this Python script
Finally, just perform your S/R operation
Et voilà !
Here are the links to that valuable script and the discussions about that topic :
https://notepad-plus-plus.org/community/topic/13754/replace-1-lines/29 ( The last version of the Claudia’s Python script )
Scott Sumner last edited by
Perhaps the OP would be interested to know (if s/he doesn’t know already) that replace operations can be stored as a macro and then run later via a simple custom-named choice on the Macro menu. To set this up, experiment with these Macro menu (or toolbar, in some cases) items:
- Start Recording
- Stop Recording
- Save Currently Recorded Macro.
Note that when recording a very simple macro, for example, one that does a single replace operation, that you only need to wrap the Start and Stop recording operations around the button press that actually does the action (the Replace button in this case).
All of the other actions in setting up a replacement (filling in the Find what zone, the Replace with zone, the search options and mode, etc) aren’t recorded as you navigate the user interface, but rather are “snapshotted” into the macro when the Replace button is pressed.
I find this handy as I can get the actions correct (e.g. try them out) without worrying about putting a bunch of actions I end up not wanting into the macro. When I’m happy with my replacement parameters, I start recording, press Replace, stop recording, save/name it, and I am DONE.
guy038 last edited by