Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2005

Tip: Looking for answers? Try searching our database.

Postal code processing with .NET regex

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Surfdog - 30 Sep 2005 17:07 GMT
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.
Chris Dunaway - 30 Sep 2005 19:27 GMT
> 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
Surfdog - 30 Sep 2005 19:42 GMT
Thanks, Chris. I'll do that and I appreciate the link :).

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.