Batch replacing questions
-
Hello,
I am trying to batch replace through multiple files a certain line. But while usually it’s easy with the Find in Files interface , in this case i’m puzzled as the line i want to replace is not always exactly the same : By example i want to replace that line
blablabla = number
by
blablabla = 0My problem there is that “number” in the blablabla = is not always the same through all the files, but i need all of them to be = 0 in the end result, so i searched a bit and noticed some people mentionning “wildcard” and suggesting to look into “extended” and “regular expression” that you can tick in the bottom of the “Find in Files” box.
So searching the online manual i ran into
https://npp-user-manual.org/docs/searching/#extended-search-mode
and
https://npp-user-manual.org/docs/searching/#regular-expressions
that does not mean anything to me as unfortunately it seems wrote for people that already know those controls and how to use and code them (and as those provide no example of each controls figuring it out on my own … well ) .So please, anyone can help me in my problem ?
-
@Sanc-Tuary said in Batch replacing questions:
it seems wrote for people that already know those controls and how to use and code them
Well, kind of.
But it is a big topic not just belonging to Notepad++, so the manual doesn’t attempt to reinvent the wheel…
First, forget “Extended” mode – it won’t help. “Regular expression” land is where you want to be.
You might be interested in the
\d
regular expression…that one finds a “digit”, i.e., 0-9. So:Find:
blablabla = \d
Search mode: Regular expressionThis would match
blablabla = 4
orblablabla = 7
or etc.But it would not match
blablabla = 24
exactly because that is two digits. It would match that asblablabla = 2
which isn’t what you want.So maybe switch to:
Find:
blablabla = \d+
Search mode: Regular expressionwhich would match
blablabla = 24
orblablabla = 357
or etc.But maybe “number” in your question could be a negative number, or a positive number with a leading
+
, or a floating point number, or one in exponential notation…And whew, that got complicated fast, didn’t it?
There are some good references HERE and one of them will lead directly HERE which is (or could be) more specific to your problem.
-
@Alan-Kilborn
Thank you very much, your examples really helped, the \d+ and how / where to use it solved my problem. -
@Sanc-Tuary said in Batch replacing questions:
the \d+ and how / where to use it solved my problem
I caught you a fish today. Tomorrow, catch your own by reading some of the references cited above.