Split address string with text and number

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
kongharald
Posts: 3
Joined: Sat Oct 11, 2003 7:17 pm
Contact:

Split address string with text and number

Post by kongharald »

I have a file with addresses with a format like this

Code: Select all

Bigstreet 11a
East Old avenue 2b
Mean Street 4
Shopping district 1, 2b
Is there a Reg.exp that may insert a tab before the first digit in each line?
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Search for
^([^0-9]*)([0-9])
replace by
\1\t\2


^([^0-9]*)([0-9]) searches for the beginning of the line, followed by any number of non-digits (remembering all those non-digits) followed by a digit (remembering this digit).

\1 is the first remembered part (i.e. the non-digits), \t the tab character, \2 the second remembered part (i.e. the digit)
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

MudGuard wrote:Search for
^([^0-9]*)([0-9])
replace by
\1\t\2
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
User avatar
SteveH
Posts: 327
Joined: Thu Apr 03, 2003 11:37 am
Location: Edinburgh, Scotland
Contact:

Post by SteveH »

One issue with this solution (I came up with something similar) is that it retains a space before the inserted tab character. I wasn't sure if kongharald just wanted a tab inserted or the space before the digit replaced.
Post Reply