I need to remove everything but numbers and, if exists one character from a string. It's a street name I need to extract the house number of. It is possible that there is some more content after the string, but not neccessarely.
The original string is something like
Wagnerstrasse 3a platz53,eingang 3,Zi.3005
I extract the street with number like this:
preg_match('/^([^\d]*[^\d\s]) *(\d.*)$/', $address, $match);
Then, I do an if statement on "Wagnerstrasse 3a"
if (preg_replace("/[^0-9]/","",$match[2]) == $match[2])
I need to change the regex in order to get one following letter too, even if there is a space in between, but only if it is a single letter so that my if is true for this condition / Better a regex that just removes everything but below:
Wagnerstrasse 3a <-- expected result: 3a
Wagnerstrasse 3 a <--- expected result 3 a
Wagnerstrasse 3 <--- expected result 3
Wagnerstrasse 3 a bac <--- expected result 3 a