Split Mail Address into it’s parts using RegEx pattern

I develop a lot of data parsers and continuously run into composite mailing addresses that require to be split into their meta collections. The following Regex pattern will reformat these two style addresses into XML tag elements.

SAMPLE ADDRESS DATA:

1200 Ocean Rd., Narragansett, RI 02882
1200 Ocean Rd., Narragansett, RI 02882-1234

FIND PATTERN USING REGEX:

REPLACE WITH XML FORMAT:

OUTPUT:

<address>1200 Ocean Rd.</address>
<city>Narragansett</city>
<state>RI</state>
<zip>02882</zip>

Author: Richard Soares

I’m a freelance software developer with more than 20 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork.