2

I have a address field that I want to separate in street name and house-number suffix, first part of address (street-name) is not a problem but the second part for the house-number suffix is a bit tricky.
In bold is the part that I want to select:

  • 1st street 25
  • 1st street 25 a
  • 1st street 25b
  • 1st street 25-ab

And this is the regex code that I use in c# to output only the house number suffix, but so far no luck selecting the bold parts:

{
  string sNum = AdField;
  string sRep = @"\s(\d[^\s]*[ A-Z]\w*)?(\d\w\s)\s?(.+)";
  string output = Regex.Match(sNum, sRep).Value;

  return output;
} 
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
H35am
  • 768
  • 2
  • 12
  • 32

2 Answers2

4

I think think you can do it with this demo
the regex is

\d+(\s|-)?\w*$
marvel308
  • 10,288
  • 1
  • 21
  • 32
0
[a-z]+ ?([0-9]+ ?\-?[a-z]{0,2})

Explaination

[a-z]+

catching the last part of the streetname

 ?

watch the space in front of the ? means 1 or 0 spaces

[0-9]+

1 or more numbers

 ?

another optional space

\-?

optional dash (-)

[a-z]{0,2}

0 to 2 letters

online Thomas
  • 8,864
  • 6
  • 44
  • 85