Help to replace signs
-
Hello. I got a huge text doc and I can not replace signs in document, I tried only replace, but it replaces all document. I have a text
numric-:N1CK# deal OTHER!
SIGN-:J0HN# deal ADAM!
Zumric-:M1KE# deal TOGETHER!
numric-:SV3NN# deal KORY!
VOTE-:K!ND@# deal TOGETHER!
Zumric-:N4C# deal TOGETHER!
VOTE-:G@RR3TH# deal OTHER!and I need
numric-:NICK# deal OTHER!
SIGN-:JOHN# deal ADAM!
Zumric-:MIKE# deal TOGETHER!
numric-:SVENN# deal KORY!
VOTE-:KINDA# deal TOGETHER!
Zumric-:NAC# deal together!
VOTE-:GARRETH# deal OTHER!I need only replace text between (:) and (#) chars , want to replace 1-I, 0-O, 3-E, @-A etc.
Please help me to do that -
@serg-oth said in Help to replace signs:
want to replace 1-I, 0-O, 3-E, @-A etc.
You can do that using this technique:
Find:
(0)|(1)|(2)|(3)|(4)
Replace:(?1O)(?2I)(?3Z)(?4E)(?5A)
Search mode: Regular expression
Note: I guessed about the2
->Z
transformation!For the “etc” part you just add more to the pattern.
Example, replace5
withS
:
Find:(0)|(1)|(2)|(3)|(4)|(5)
Replace:(?1O)(?2I)(?3Z)(?4E)(?5A)(?6S)
Note also that the number following the
?
s in the Replace expression is one more than what you might think!I need only replace text between (:) and (#) chars
For that part, we can apply the technique shown here:
https://community.notepad-plus-plus.org/post/62799
specifically:
SEARCH
(?-i:BSR|(?!\A)\G)(?s:(?!ESR).)*?\K(?-i:FR)
REPLACERR
where BSR =
:
, ESR =#
, FR and RR are as I showed above.Thus, completely, we have:
Find:
(?-i::|(?!\A)\G)(?s:(?!#).)*?\K(?-i:(0)|(1)|(2)|(3)|(4))
Replace:(?1O)(?2I)(?3Z)(?4E)(?5A)
Search mode: Regular expression
Note: You must use Replace All to do the replacements -
@Alan-Kilborn could you,please write. how to convert it back as in begining?
from
numric-:NICK# deal OTHER!
SIGN-:JOHN# deal ADAM!
Zumric-:MIKE# deal TOGETHER!
numric-:SVENN# deal KORY!
VOTE-:KINDA# deal TOGETHER!
Zumric-:NAC# deal together!
VOTE-:GARRETH# deal OTHER!to
numric-:N1CK# deal OTHER!
SIGN-:J0HN# deal ADAM!
Zumric-:M1KE# deal TOGETHER!
numric-:SV3NN# deal KORY!
VOTE-:K!ND@# deal TOGETHER!
Zumric-:N4C# deal TOGETHER!
VOTE-:G@RR3TH# deal OTHER!only replace text between (:) and (#) chars
5 stars for you MAN! You are AWESOME)!!!
-
@serg-oth said in Help to replace signs:
could you,please write. how to convert it back as in begining?
Hmm, I thought my explanation of the forward transform would have been enough to make something like that fairly obvious. Do you have any thoughts as to how you might do the reverse transform, other than asking me to do it?
-
@Alan-Kilborn its only for me to know that kind of commands. Education only. Sorry for taking your time,man
-
@Alan-Kilborn said in Help to replace signs:
Find: (0)|(1)|(2)|(3)|(4)
Replace: (?1O)(?2I)(?3Z)(?4E)(?5A)So if we look back at that…
We are looking for
0
or1
or2
or3
or4
(from the “Find” expression)When we find one of those, at replace time we look at what we found, and replace it with something else.
0
goes toO
,1
goes toI
, etc.So, how hard is it to go the other way?
You’d just swap the values in the find/replace specification.
So the first one might be:
F:(O)
R:(?10)
Get it?
-
@Alan-Kilborn said in Help to replace signs:
R: (?10)
Actually, it is not that simple. :-(
?10
here is interpreted as a10
not as a1
followed by a0
.Ok, since that may not be easy to understand, I’ll give you the full solution to the reverse transform, rather than assisting you to think it through:
Find:
(?-i::|(?!\A)\G)(?s:(?!#).)*?\K(?-i:(O)|(I)|(Z)|(E)|(A))
Replace:(?{1}0)(?{2}1)(?{3}2)(?{4}3)(?{5}4)
Search mode: Regular expression
Note: You must use Replace All to do the replacements -
@Alan-Kilborn I got it, bro. What about A-@, S-$, i-!
F(A)
R(?@)
right? -
I got it bro
You are at least thinking about how to apply it! Which is good!
F(A)
R(?@)
Close.
OK, so here’s the formula:
In the Find expression, you look from left to right at the parentheses groupings,
(
and)
. The first pair is group 1, the second pair is group 2, etc.Then, in Replace, you use the group number after the
?
.So, in this simpler case:
Find:
(O)|(I)
Replace:(?{1}0)(?{2}1)
you want to replace group number 1 (the
O
match) with0
, so you use?{1}
before the0
in the replace.
Similarly, theI
is in group number 2 in the find, so you refer to it as?{2}
in the replace.You can think of the
?
as “is this group number matched?”. -
@Alan-Kilborn Thanks a lot. Everything is clear