We help IT Professionals succeed at work.

Trimming out just the town/city names from a list using regular expressions

James Froggatt
James Froggatt used Ask the Experts™
on
I have a long list of towns/cities, here's a sample:

1      Tórshavn      STR      13,335
2      Klaksvík      NOR      4,842
3      Hoyvík      STR      4,124
4      Argir      STR      2,188
5      Fuglafjørður      EYS      1,541
6      Vágur      SUD      1,342
7      Vestmanna      STR      1,236
8      Miðvágur      VAG      1,120
9      Sørvágur      VAG      1,108
10      Saltangará      EYS      1,012

I wish to efficiently create a list of just the towns/cities in Notepad++ so it looks as follows;

Tórshavn
Klaksvík
Hoyvík
Argir
Fuglafjørður
Vágur
Vestmanna
Miðvágur
Sørvágur
Saltangará

In Notepad++ what regular expression can I use to do this in the Replace "Find it" box.

Thank you
regexp.jpg
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dimitris MaleasData recovery engineer

Commented:
In notepad++ you can delete the columns very easy with the following procedure
Press and hold the SHIFT + ALT keys, and move down using the DOWN arrow on the keyboard (while still holding SHIFT + ALT).

Author

Commented:
I can use that to remove the number and space up to the first character of the town name, but then there's no clear column to use after that to delete after the town/name i.e.


Wien      Wien      1,897,491
Graz      Stm      288,806
Linz      OÖ      205,726
Salzburg       Sbg      154,211
Innsbruck      Tir      132,110
Klagenfurt      Ktn      100,817
Villach      Ktn      62,243
Wels      OÖ      61,727
Sankt Pölten      NÖ      55,044

So I think I need a regular expression now, to the effect of;

"On each line select everything after the first space after the first word "

Thanks
Data recovery engineer
Commented:
The solution in 2 steps with regular expressions:
1) ^\S+\s+(.+)$  with \1
2) ^([^ ]*).* with \1

Do not forget to put cursor upper left each time!

Author

Commented:
Thank you all, this helped me sort this data out.