mass replace diffrent text in file
-
i have a large text file where i would like to replace an extension with regex, help me
example
Z site:com Y site:fr X site:uk
to:
Z site:pl Y site:pl X site:pl
-
@Clyde-Parker said in mass replace diffrent text in file:
where i would like to replace an extension with regex,
Using the Replace function we have
Find What:(?-s)([^:]+).+$
Replace With:\1:pl
As this is a regex the “search mode” needs to be regular expression. Wrap around can be ticked.You can either hit the “Replace button” to see each change, or the Replace All button to do the entire file in 1 go.
Terry
PS this assumes there is ONLY 1
:
in the line, immediately before the “extension” you wish to change. As you haven’t really shown us “real” data this is assumed. -
@Terry-R said in mass replace diffrent text in file:
PS this assumes there is ONLY 1 : in the line
As a matter of interest the easy way to determine if ANY line has more than 1
:
is to run a regex using the “Find” function and using the “Count” button.
So the regex could be (my version, there are many ways to do this)
Find What:(?-s)^([^:]+)*:([^:]+)*:
Again as a regex the search mode must be “regular expression” and you should either have the cursor at top of file, or make sure “wrap around” is ticked so that it can check the entire content of the file. After clicking the “Count” button the bottom of the “Find” window will show you:
“Count: xx matches from caret to end of file” (my setting was not “wrap around”) or “in entire file” and xx is the number 0 or more.Terry
-
Maybe the OP wants to replace only
com
,fr
, anduk
after a:
, which is easy to do, but why bother unless the OP clarifies the need.Plus OP is starting to become a “regex taker” and should be requested to show what he’s tried and failed with, before receiving additional help.
-
Hi, @clyde-parker, @terry-r and All,
Again, fairly easy :
Like @terry-r, I assume just one
:
per line, followed with a country identifier, ending the current lineSEARCH
(?<=:)\l+
REPLACE
pl
The search regex tries to match the greatest range, non empty, of lowercase letters, which is immediately preceded with a colon
:
You must use the
Replace All
button, exclusively, if your N++ version is prior thev7.9.1
version. Else, theReplace
button can be used as well ;-))Best regards,
guy038
-
@Alan-Kilborn said in mass replace diffrent text in file:
Maybe the OP wants to replace only com, fr, and uk after a :
True, we often deal in ambiguities. The OP will need to expand on request if current solution does NOT meet his needs.
Terry
-
Hi, @terry-r and All,
To count all the lines which contain, at least, two
:
signs, this regex should be enough :SEARCH
(?-s):.*:
Indeed, we do not have to care about text before the first colon and text after the second colon ;-))
And, if you click on the
Find Next
button it matches all the range of characters between these two colons, included !Best Regards
guy038
-
thanks everyone for your help, i’ve got how to make this work