Remove blank spaces between numbers

A place to try and solve your RegEx problems.
Post Reply
Shades
Posts: 4
Joined: Thu Jan 02, 2014 3:20 pm

Remove blank spaces between numbers

Post by Shades »

Hi,

I have a couple of text files that contain transcripts from conversations, text and numbers. In some files, the numbers have a blank space between them.
For example:

We will come in on Saturday to upgrade 2 8 servers. Those are the last machines on the list, so we'll have completed all 1 3 4 servers.

In that example, I'd need to find the 2 8 and the 1 3 4 and remove the space so the outcome is

We will come in on Saturday to upgrade 28 servers. Those are the last machines on the list, so we'll have completed all 134 servers.

I can find the text by searching for [0-9] [0-9] but I've not figured out what I would replace it with to remove the spaces. Plus I'm sure there's more intelligent ways to find the separator spaces between numbers.

Any help would be appreciated.
User avatar
DigitalVolcano
Site Admin
Posts: 1717
Joined: Thu Jun 09, 2011 10:04 am

Re: Remove blank spaces between numbers

Post by DigitalVolcano »

This example using lookahead works well in the tester:

regex:

Code: Select all

\b(\d+)\s+(?=\d+\b)
replace:

Code: Select all

$1
Disclaimer: I got it from here:
http://stackoverflow.com/questions/6929 ... tween-them
Post Reply