Postal code processing with .NET regex

S

Surfdog

Hello all,

I'm unable to figure out how to process the zip codes with regexes.
We have a custom component that takes a find pattern, a replace
pattern, and the input value, and will output the processed result
string. At the moment we're trying to clean up some zip code data
that has the following inconsistencies, for example:

99d999
99999d
V2X 4B4
unknown
tyrone
SDHJSHD
sasas
na
DSJKDJSKDJ
DKSLDKSLKD
D
999999
99999
99520
99207-4771

I would like to clean up the invalid values and return a null string
instead. If part of the value is valid, I'd like to return that and
drop the rest. So for a given zip code value:

If any of the first five characters are not a digit, select the entire
value and replace it with nothing ("")

If the first five characters are digits, and the next character is a
hyphen, get the next four characters. If they are digits, get all 10
characters. If not, get the five digits from the left


If there are first nine characters are digits, bring only those nine
back


Is it possible to handle this level of conditional processing in a
regular expression? They can run individually or however it needs to
be. I've experimented with lookarounds and regex conditionals but am
not able to figure it out.

Any help is greatly appreciated. Thank you in advance for your time.
 
C

Chris Dunaway

Surfdog said:
Hello all,

I'm unable to figure out how to process the zip codes with regexes.
We have a custom component that takes a find pattern, a replace


Try this web site:

http://www.regexlib.com/

do a search for postal codes and see if any of the patterns will work
for you.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top