Page 1 of 1

Split address string with text and number

Posted: Mon Oct 30, 2006 7:21 pm
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?

Posted: Mon Oct 30, 2006 8:45 pm
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)

Posted: Mon Oct 30, 2006 9:42 pm
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

Posted: Tue Oct 31, 2006 8:18 am
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.