Плагин расширенного поиска
-
Добрый день.
При работе с поиском и заменой текста регулярно возникают задачи, которые не решает стандартный поиск.
К примеру:- надо найти текст-1 и от текста-1 найти вверх или вниз вхождение текста-2 и далее заменить текст-1 или текст-2 на текст-3.
- надо найти текст-1 и от текста-1 переместиться на заданное количество символов влево или вправо и далее сделать замену начиная с этой позиции
Выше приведенные поиск и замену, можно сделать рекурсивным на заданную глубину.
Есть ли плагин в Notepad, который решает такие задачи ?
-
I used Google translate on your post to get:
Good afternoon.
When working with text search and replacement, tasks regularly arise that the standard search does not solve.
For example:- 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.
- you need to find text-1 and move from text-1 to the specified number of characters to the left or right and then make a replacement starting from this position
The above search and replace can be made recursive to a given depth.
Is there a plugin in Notepad that solves this problem?
The forum does ask that you post in English preferably. Since it is you who wants help this would be the polite thing to do.
So if the translation is correct then it does seem possible to complete the tasks with regular expressions. However without concrete examples it is doubtful you will get any help.
Read the pinned post at the start of the “Help Wanted” section called “Please Read This Before Posting” on how to provide examples and you may get shown how to do it. The Help Wanted section would be a more accurate area to post in.
Terry
-
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 notabctext-1xyz
” -
The string as in the sentence “This
abctext-1xyz
is right, as well asabc text-1 xyz
”
Secondly, do you mind about the case of letters in
text-1
and/ortext-2
?In other words, must the string
text-1
have :-
The exact case
text-1
-
Are the
Text-1
,TEXT-1
,text-1
andtExT-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 fromtext-1
find up or down the occurrence oftext-2
and then replacetext-1
withtext-3
-
(B) you need to find
text-1
and fromtext-1
find up or down the occurrence oftext-2
and then replacetext-2
withtext 3
But, in this case, this could also be expressed as :
-
(A) Change
text-1
withtext-3
, if current file contains, at least, one occurrence oftext-2
-
(B) Change
text-2
withtext-3
, if current file contains, at least, one occurrence oftext-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
andN
characters on the right, use the search regex :
(?-s)text-1.{
N}\K
- To get the zero-length position, before
text-1
andN
characters on the left, use the search regex :
(?-s)\K(?=.{
N}text-1)
See you later,
Best Regards,
guy038
-