I want to delete everything accept my ip and port on each line.
-
Delete multiple lines
I want to delete everything accept these numbers 76.247.131.161:57524<— this number changes and I want to keep on each line
I cant figure out how to do it correctly…21 76.247.131.161:57524, Port:5524, 27012, RCON:27300, DIR:21, PID:45696, Name:
22 76.247.131.161:57544, Port:5544, 27022, RCON:27305, DIR:22, PID:23584, Name:
23 76.247.131.161:57564, Port:5564, 27032, RCON:27310, DIR:23, PID:26192, Name:
24 76.247.131.161:57584, Port:5584, 27042, RCON:27315, DIR:24, PID:51116, Name:so it looks like this
76.247.131.161:57524
76.247.131.161:57544
76.247.131.161:57564
76.247.131.161:57584 -
Hello @upperking, and All,
@upperking, welcome to the Notepad++ Community !
Elementary, with a simple regex S/R :
-
Open the Replace dialog (
Ctrl + H
) -
Type in
(?-is),\x20?Port.+
in the Find what : zone -
Leave the Replace with: zone
EMPTY
-
If necessary, tick the
Wrap around
option -
Select the
Regular expression
search mode ( IMPORTANT ) -
Click once on the
Replace All
button or several times on theReplace
button
Et voilà !
Notes :
-
The in-line modifiers
(?-is)
forces the search to be performed in a non-insensitive way and the dot.
to match a single standard character only -
Then, the part
,\x20?Port
looks for a comma, followed with an optional space char and the string Port, in that exact case -
Finally, the part
.+
search for any non-null range of standard characters -
As the Replacement zone is
empty
, the range, Port..........
, ending any line is deleted
Best Regards,
guy038
-
-
holy crap that was amazing thank you…
One last issue how do I delete numbers on each line like example.
https://gyazo.com/1bc37153673f725c00bbae338937aa37 -
Hi @upperking,
Oupppss ! I should have read your post more carefully ! We must take the leading numbers in account ;-))
So, change the Find and Replace zones, as below :
SEARCH
(?-is)^\d+\x20(76\.247\.131\.161:\d+).+
REPLACE
\1
Notes :
-
Beware : if the IP address is not exactly the address
76.247.131.161
, nothing is then replaced -
The part
^\d+\x20
represents any number, beginning a line and followed with a space character -
The dot meta character
.
is escaped with the\
to be considered as a literal -
The group
1
is the string 76.247.131.161 followed with a colon, followed with the port number, which is rewritten, during the replacement phase
Cheers,
guy038
-