mza box
mza box

Reputation: 67

How to remove empty spaces Notepad++ using regex?

I have a textfile contains lines with below:

IP              Ports           
1.160.0.224     8080            
1.160.1.49      8080            
1.160.1.70      8080            
1.160.1.170     8080            
1.160.1.239     8080            

I want to use notepad++ regex to remove all empty space and just leave the IP:PORT.

For example below:

1.160.0.224:8080
1.160.1.49:8080
1.160.1.70:8080
1.160.1.170:8080
1.160.1.239:8080

Upvotes: 1

Views: 18920

Answers (5)

Akshay Tyagi
Akshay Tyagi

Reputation: 99

Find--> (\s*)(.\*?)(\s*) and ReplaceWith--> \2

Upvotes: 1

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521239

Find:

(\d)\s+(\d+)\s+

Replace:

$1:$2\r\n

This solution takes into account that you may have a header at the top of your table which you don't want modified during the replacement. It also takes into account that your original data appears to have extra whitespace after the port number 8080.

Here is a screen capture showing you what your find/replace window should look like:

enter image description here

Upvotes: 2

Liping Huang
Liping Huang

Reputation: 4476

You can use \s+ to match one or more whitespace, to use notepad++, you can replace based on the "regular expression", but you still need to manually replace by "Find Next" and "Replace" one by one to choose where you want to repalce.

enter image description here

Upvotes: 2

Andriy Kryvtsun
Andriy Kryvtsun

Reputation: 3344

Use this search regexp \s+ (one or more empty characters)

Upvotes: 2

J Earls
J Earls

Reputation: 1812

I don't know the Notepad++ UI, but your pattern should be  * (a space followed by *), and you replacement should be :

Upvotes: 1

Related Questions