Replacing variable number of blanks?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Replacing variable number of blanks?

Post 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
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post 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: :_
Last edited by ak47wong on Sat Sep 28, 2013 11:36 pm, edited 1 time in total.
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Post by terrypin »

Thank you, that's perfect, and so simple too - now I've seen it!

--
Terry, East Grinstead, UK
Post Reply