I am currently trying to improve the readability of some of my python scripts by adding
spaces around the equal signs. For example, currently an assignment looks like this:
foo=4
bar[index]=4
and I want to change it to:
foo = 4
bar[index] = 4
I've already found the following answered question Notepad++: Search and Replace with Regular Expression which suggests that using the following regex in "find what" should work:
(?<=[w])])=(?=w)
Notepad++ correctly finds all corresponding equal signs, but it doesn't replace them, no matter what I try to replace them with. I am now using:
([w])])=(w)
in "find what" together with:
1 = 2
in "replace with", which does the job. However, I don't understand why the initial regex doesn't work, especially as it (well, something equivalent to it) is marked as correct in the linked question. It doesn't work in either Notepad++ 6.6.1 or 6.6.8. I am not very familiar with regular expressions and this is the first time that I am using them in Notepad++, so I would appreciate any help.
Edit:
To clarify: I didn't leave the "replace with" field empty in any of my attempts, but always filled it with something, either with =
or some other string. For my initial regex, I didn't use 1 = 2
.
But I think I have identified the problem. I've tried all the suggestions so far, but none of them seemed to work. But as soon as I clicked on "replace all" instead of "replace", Notepad++ did replace everything correctly, even with my initial regex. I am not sure if this is the intended behaviour.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…