how to multi replace?
-
Hello dear everybody,
I searched for a possibility to do Multi search and replace -Jobs in one turn. Is this possible native and I just didn’t find? Or is it possible trough macros?
Thanks in advance
-
Hello @Thomas-Hofmann,
what do you mean by multi-search and replaces
- first looking for abc and replace with xyz
- next looking for def and replace with rts
and so on?
If so, it could be that it is natively supported but depends if
it can be searched and replaced by regexes.
If not, could you explain it in more detail.
And of course there are other ways like using scripting languages like lua, python etc…
Cheers
Claudia -
Hello Claudia,
it is just as you did guess. I wanted multiple search-/replace-jobs in one Job.
repalce “aaa” with “bbb”
replace “ccc” with “ddd”
and so onregexp should be applicable.
best regards
-
Hello Thomas,
ok, is it always the same data you wanna search for and replace with?
Then it might be even possible to record a macro.
Maybe you wanna give it a try first?Click Macro->Start Recording
Press CTRL(STRG)+h
Fill in what you are searching for
and with what it needs to be replaced.
Replace dialog should be still open, press ALT+A
now put in what needs to be searched and replaced next.
Press ALT+A again, do this until it’s done.
Close Replace dialog window and click Menu->Stop Recording.To see if the macro really works press CTRL(STRG)+Z as many times as need to
get the initial version of the document then click Macro->Playback.If it results in what you want Click->Macro->SaveCurrentRecordedMacro and give it a meaningful name.
From now on, it should appear in the Macro Menu.If this doesn’t help or you want to go the regex way we need to have your data and the
information what you want to search and replace with.Cheers
Claudia -
Hello Claudia,
I will try this.
Thanks and best regards, Thomas
-
Hello Thomas and Claudia,
@Claudia :
Ah! I didn’t know that N++ was able to recorder successive S/R, in an unique macro ! This may be useful, sometimes. By the way, you can, either, hit the ALT + A shortcut or click, with the mouse, on the Replace All button. You may, also, choose the options with the mouse. It doesn’t matter :-))
@Thomas :
If you just need less than, let’s say, five S/R, you’d better choose regular search and replace expressions, instead.
Indeed, for instance, with the search field, below :
(aaa)|(ccc)|(eee)|(123)
and the replace field below:
(?1bbb)(?2ddd)(?3fff)(?{4}456)
-
The string aaa is changed into bbb
-
The string ccc is changed into ddd
-
The string eee is changed into fff
-
The string 123 is changed into 456
Notes :
-
Be sure that the Regular expression search mode is checked
-
The search regex tries to match, either, the strings aaa, ccc, eee or 123, which are stored, accordingly, as group 1, 2, 3, and 4
-
The replace regex force to change these search strings with the strings bbb, ddd, fff or 456, accordingly to the matched group
-
Just note that the syntax
?4
is simply re-written as?{4}
for NOT mixing the group number, with the literal following digits ( 456 ), which must replace the string 123 !
Best Regards,
guy038
-
-
Hello @guy038,
well, to be honest, I never tried it - I hope Thomas understood that I was talking about normal searches.
I should have mentioned it more clearly, for sure.Cheers
Claudia