Wanting to change every other time a word comes up.
-
Looking to make a change every other line of code comes up. this comes up thousands of times in my script and I need to change every other time it comes up.(… represents text that is different in each line and there is a lot of lines between)
I just want to change every other “space” to space2
Can this be done?
From this:
CODE : …\space.vmdk
… x 10-20 random lines between
CODE : …\space.vmdkto this
CODE : …\space.vmdk
… x10 - 20 random lines between
CODE : …\space2.vmdk -
Find:
(?-is)^\QCODE : ...\space.vmdk\E(?:.*\R){10,20}\K\QCODE : ...\space.vmdk\E
Replace:CODE : ...\\space2.vmdk
Search mode: Regular expression -
If every appearance of
\space.vmdk
“counts” — that is, it doesn’t appear in comments or other contexts that aren’t part of the “every other instance” rule — then this is easy:Open Search | Replace… from the menu, and enter:
Find what :
\\space\.vmdk.*?\K\\space\.vmdk
Replace with :\\space2.vdmk
Search Mode : Regular expression
. matches newline : CHECKEDthen click Replace All.
If context matters, then it gets more complicated. I’m not sure if “CODE : ” in your sample means literally those characters at the start of a line, so I’m not going speculate on what might be needed without more information.
Note: Because of the
\K
in the above expression, you must use Replace All; if you try to test with individual find and replace steps, it won’t work. Do it this way:Find what :
(\\space\.vmdk.*?\\space)\.vmdk
Replace with :($1)2.vdmk
Search Mode : Regular expression
. matches newline : CHECKEDif you need or want to do sequential find and replace.
-
Hi, thanks for your reply the actual code doesn’t have the text “… x 10-20 random lines between” I was using that as a example that there is a random number of lines between the text
also the … are just shortened down text to make it easier to see. sorry for any confusion
Thanks for your response but unfortunately this didn’t work. I do appreashate the effort though. someone else posted a solution that worked.
-
This post is deleted! -
@Coises
Thanks, this did exactly what I needed! -
My solution did work, you just didn’t ask a good question.
@Coises just mentally fixed your question’s problems before answering, I guess.
We don’t always read minds the same way here; I tend not to try.EDIT: You did say “… represents text that is different in each line and there is a lot of lines between” and I took that into account for the “random” lines, but I truly thought you meant it literally for the “space” lines. So, sorry about that.
-
Sorry that one was on me, im still new at using notepad++ and wasn’t sure how to word my question. I do again apricate your effort.