Hello, @pavel-san, @terry-r and All,
As @terry-r said, there are a lot of questions concerning your requests !!
First, when you speak of text-1 do you mean :
The word, as in the sentence “This abc text-1 xyz is right, but not abctext-1xyz”
The string as in the sentence “This abctext-1xyz is right, as well as abc text-1 xyz”
Secondly, do you mind about the case of letters in text-1 and/or text-2 ?
In other words, must the string text-1 have :
The exact case text-1
Are the Text-1, TEXT-1, text-1 and tExT-1 syntaxes all OK ?
Idem for text-2 !
Now, your first statement :
you need to find text-1 and from text-1 find up or down the occurrence of text-2 and then replace text-1 or text-2 with text-3.
can be slipt into two different goals :
(A) you need to find text-1 and from text-1 find up or down the occurrence of text-2 and then replace text-1 with text-3
(B) you need to find text-1 and from text-1 find up or down the occurrence of text-2 and then replace text-2 with text 3
But, in this case, this could also be expressed as :
(A) Change text-1 with text-3, if current file contains, at least, one occurrence of text-2
(B) Change text-2 with text-3, if current file contains, at least, one occurrence of text-1
Case (A) could be achieved with the regex S/R :
SEARCH (?s)(?=.*text-2).*?\Ktext-1
REPLACE text-3
Tick the Wrap-around option
Select the Regular expression search mode
Click once on the Replace All button
Case (B) could be achieved with the regex S/R :
SEARCH (?s)(?=.*text-1).*?\Ktext-2
REPLACE text-3
Tick the Wrap-around option
Select the Regular expression search mode
Click once on the Replace All button
Finally, your second statement is :
You have to find text-1, and then move from the text-1 to the left or to the right by a given number of characters, and then replace it starting from this position
Many questions !
Do you want to find all occurrences of text-1 or a specific one ?
What you want to replace ( an exact number of chars, the next word, an exact string or even some text splited on several lines ? )
Anyway, here is a first idea :
To get the
zero-length position, after
text-1 and
N characters on the
right, use the search regex :
(?-s)text-1.{N}\K
To get the
zero-length position, before
text-1 and
N characters on the
left, use the search regex :
(?-s)\K(?=.{N}text-1)
See you later,
Best Regards,
guy038