Need help with Replacing lines
-
I have about 100k lines like these
LoydNova47:TEHHA3HFW35GG:cc9sttdcb6tkb8z31hs7i3p3sss8rx:hongjgd45td5wnumnpe4gzwn3iiiglsq09d0vptyll9mrc7p9d
PierreIncendi5fary7:UNM7EAG4QBPHGY:vr2534igqrj1llisopis4l1yc1z4py:6p22mq1ruxfr8i3nz0cihl2bby6j944r4hcz602w9x99neftrd
KlinklangHJunior7:EFTEXFGP5DWKBD:n6hbd3869c0h48kzg8r89rejg344qb:r8hq5i2yoladarotzkhlhe82kucirqmn26t9mne7jwjbuwiy3w
And i want to change each line to only this
LoydNova47:TEHHA3HFW35GG
PierreIncendi5fary7:UNM7EAG4QBPHGY
KlinklangHJunior7:EFTEXFGP5DWKBD
can someone help me how to do that? -
Hello @ilya-levadny and All,
Actually, you want to delete all characters located after the second colon character, included, of any line
Indeed, not difficult with regular expressions !
-
Open the Replace dialog (
Ctrl + H
) -
SEARCH
(?-s)^(.+?:.+?):.+
-
REPLACE
\1
-
Select the
Regular expression
search mode -
Check, preferably, the
Wrap around
option -
Click, once on the
Replace All
button or several times on theReplace
button
An other formulation would be :
-
SEACRH
(?-s)^.+?:.+?\K:.+
-
REPLACE
Leave EMPTY
This time, due to the
\K
syntax you must use theReplace All
button, exclusively
Notes :
-
The
(?-s)
in-line modifier means that dot (.
) matches any single standard character, only -
The
.+?:
part looks for the shortest non-null range of characters till a colon (:
) -
The part between parentheses (
.+?:.+?
) is stored as group1
, which must be rewritten, during the replacement phase -
At the end, the
.+
syntax represents the rest of the line, after the second colon char, included, of the current line -
In the second version, after matching the implicit group
1
, the\K
syntax resets the regex engine, so the final overall match is the part:.+
which corresponds to the second colon char with all the subsequent chars of current line, which are deleted as the replacement zone is empty
Best Regards,
guy038
-