Page 1 of 1

Replacing variable number of blanks?

Posted: Sat Sep 28, 2013 6:40 am
by terrypin
How would I change a list with entries like this

Code: Select all

United Kingdom             2.75
Norway                          3.4
Palestinian territories      5.6
Saint Vincent and the Grenadines  6.6
Germany                       6.7
into this please:

United Kingdom: 2.75
Norway: 3.4
Palestinian territories: 5.6
Saint Vincent and the Grenadines: 6.6
Germany: 6.7

I tried this:
Replace (.*)([ ]{1})([0-9])(.*)
with
\1:\3\4

But that gave lines like

Code: Select all

United Kingdom           :2.75
So it seems that my {1} is not being interpreted as "1 or more instances of the preceding element" as I'd read somewhere.

How *do* you specify that then please?

It's obviously complicated by the need to distinguish blanks within the country name from those which need 'compacting'.

--
Terry, East Grinstead, UK

Posted: Sat Sep 28, 2013 11:48 am
by ak47wong
{1} means "1 instance of the preceding element", which is redundant. Perhaps you're referring to {1,} which means "1 or more instances of the preceding element"; the + operator is equivalent.

You can solve your problem with the following, replacing all underscores in the expressions below with spaces.

Find what: __+
OR: _{2,}
(Both mean "2 or more spaces")

Replace with: :_

Posted: Sat Sep 28, 2013 9:59 pm
by terrypin
Thank you, that's perfect, and so simple too - now I've seen it!

--
Terry, East Grinstead, UK