I want to delete everything accept my ip and port on each line.

  • Delete multiple lines
    I want to delete everything accept these numbers<— this number changes and I want to keep on each line
    I cant figure out how to do it correctly…

    21, Port:5524, 27012, RCON:27300, DIR:21, PID:45696, Name:
    22, Port:5544, 27022, RCON:27305, DIR:22, PID:23584, Name:
    23, Port:5564, 27032, RCON:27310, DIR:23, PID:26192, Name:
    24, Port:5584, 27042, RCON:27315, DIR:24, PID:51116, Name:

    so it looks like this

  • 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 the Replace 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,


  • holy crap that was amazing thank you…

    One last issue how do I delete numbers on each line like example.

  • 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, 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 followed with a colon, followed with the port number, which is rewritten, during the replacement phase



Log in to reply