Address Pattern Regular Expression
So I searched the internet for quite a while to find a street address regex that actually worked (and worked well). I didn’t manage to accomplish this, so I wrote my own. I’m keeping the address extraction algorithms and logic private, but I figured I could at least share the first part of the Regex:
Regex addressPattern = new Regex(@"(?<city>[A-Za-z',.\s]+) (?<state>([A-Za-z]{2}|[A-Za-z]{2},))\s*(?<zip>\d{5}(-\d{4})|\d{5})");
MatchCollection matches = addressPattern.Matches(text);
for (int mc = 0; mc < matches.Count; mc++)
{
string city = matches[mc].Groups["city"].Value;
string state = matches[mc].Groups["state"].Value;
string zip = matches[mc].Groups["zip"].Value;
}
[/c-sharp]