Can Notepad++ do multiple finds and replace in multiple files with Regex formulas?
-
hello. I use Notepad++ for Regex, because it is the best software that run all the regex formulas I want.
However. I sometimes need to run multiple finds and replace in multiple files, to complete some task. About 20 Finds+Replace.
\K
,\G
,^
and groups replacements doesn’t work too good in Python.But, for now I am using Python for complete this task, because Notepad++ doesn’t have any plugin to do such a Batch Processor.
So, I made a code in Python that does this job, except in Python not all the REGEX formulas works. Only few. That’s the biggest downside to Python.
But, I believe, Python Script plugin from Notepad++ can run all the Regex formula, but is not the same Python.
you can see the code here:
https://neculaifantanaru.com/en/python-regex-batch-processor-multiple-find-and-replace.html
So, my question is: Can Notepad++ do multiple finds and replace in multiple files, by a particular order? So, the find+replace process of all my Regex formulas to run even if I am not at home.
Can you can use my Python code as to make a plugin that runs multiple task (such as a Batch Processor) ?
-
@Neculai-I-Fantanaru said in Can Notepad++ do multiple finds and replace in multiple files with Regex formulas?:
I sometimes need to run multiple finds and replace in multiple files
Notepad++ doesn’t have any plugin to do such a Batch Processor.
Can Notepad++ do multiple finds and replace in multiple files, by a particular order?
If your search/replace texts are always the same, you could record many replacement operations into a macro. Then give that macro a name and run that macro when you want to do all of these replacements.
I made a code in Python that does this job, except in Python not all the REGEX formulas works. Only few. That’s the biggest downside to Python.
Python uses a different regular expression engine than Notepad++. N++ uses the Boost regex engine. So there are some differences between regex syntax. It isn’t a “downside”, just a difference.
Python Script plugin from Notepad++ can run all the Regex formula, but is not the same Python.
PythonScript is just Python with some additional objects defined for N++ objects.
Can you can use my Python code as to make a plugin that runs multiple task (such as a Batch Processor) ?
I think you’d be the best person to do this; use PythonScript.
-
I try to use macro, record and play. The problem is that I have, for example, 10 different Regex to run, and I must use
Find in Files
andReplace
in some folders. But, the folders are not the same, and I cannot edit the macro as to change every time thePATH
or even the Regex formulas.Also, I try to use
PythonScript
plugin, but is not the same as original Python, cannot make the replacements. -
OK, so then macros aren’t going to work and are out of the picture. That’s fine.
Let me try to summarize the rest of the situation:
You already have some “batch processing” of your files, just not within Notepad++. Totally external, using standard Python.
But, for some reason, you want to do what you’re doing within Notepad++ (can I ask why? If you already have something working via another means…?).
You tried to use the PythonScript plugin, but since the regular expression engine isn’t the same as standard Python’s, your replacements didn’t work. Can’t you just adjust your expressions so they do work in Notepad++.
Maybe I just don’t see the question(s) you really want the answer(s) to…
-
yes, the big problem is REGEX.
Here, with notepad++ I can run any regex, and works super. But with Python, many regex doesn’t work. So, it will be easier to use notepad++, but for now I cannot find any option to run multiple regex in a certain order…without waiting for each one to complete the task
-
@Neculai-I-Fantanaru said in Can Notepad++ do multiple finds and replace in multiple files with Regex formulas?:
Here, with notepad++ I can run any regex, and works super. But with Python, many regex doesn’t work.
OK, so I take this to mean that you’d rather use the Boost regex engine rather that the default Python
re
regex engine. That’s fine.PythonScript actually supports this. You use the
editor.rereplace()
function and it uses Boost.The reason PythonScript supports this is because people who are writing programs to script something for N++ would want their replacements to work the same way as if they were using the N++ replace interface to do replacements.
I cannot find any option to run multiple regex in a certain order…without waiting for each one to complete the task
Well, wouldn’t you want to wait for each one to complete? It seems like things could get out of sync if you didn’t.
It’s sounding more and more like a PythonScript’d solution is what you want. What parts of this are giving you trouble and what kind of help can we give you?
-
I wish I know how to use my Python code as to make multiple replacement with
Boost regex engine
.It is about some parsings and other things for optimize. Anyway, if I have more then 2.000 html files, I cannot wait for each of regex to finnish the job. I must work with some other things in the meantime.
But it will be easier for me, if the such a “Batch Processor” (with multiple search and replace) will work in background, this way I can do other things in the meantime.
PythonScript
plugin doesn’t like my Python code… -
I wish I know how to use my Python code as to make multiple replacement with Boost regex engine.
PythonScript plugin doesn’t like my Python code…
Doesn’t like your code… Hmm, well the PythonScript plugin that is officially downloadable via Plugins Admin is version 2.x – that one uses Python2 syntax. There’s a beta release of the P.S. plugin that is version 3.x – it uses Python3 syntax.
So you could change your code to use Python2, or you could use the beta plugin.
It is about some parsings and other things for optimize. Anyway, if I have more then 2.000 html files, I cannot wait for each of regex to finnish the job. I must work with some other things in the meantime.
But it will be easier for me, if the such a “Batch Processor” (with multiple search and replace) will work in background, this way I can do other things in the meantime.
Yes, this would be a problem with Notepad++, as it is a single-threaded, one-thing-at-a-time situation.
So, you’re right, for your situation, doing it with a Notepad++ solution is not going to be for the best.