473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Postal code processing with .NET regex

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.

Nov 17 '05 #1
2 2737
Surfdog wrote:
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

Nov 17 '05 #2
Thanks, Chris. I'll do that and I appreciate the link :).

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Andrew McLean | last post by:
I have a problem that is suspect isn't unusual and I'm looking to see if there is any code available to help. I've Googled without success. Basically, I have two databases containing lists of...
4
by: Dave \IT\ | last post by:
I'm looking to find out how I'd go about setting up a database where a visitor to my site could punch in their postal code, and find out how far they are from another postal code. For example,...
2
by: Axel Foley | last post by:
I used some of the excellent resources from DITHERING.COM for help in my groveling newbie attempts to cough up working form validation.... I cut and pasted bits of code to check USA ZIP codes and...
8
by: changereality | last post by:
I am trying to process raw IIS log files and insert them into a MySQL database. I have no problem accomplishing this, but the php code runs very slow. Right now, it is processing 10,000 lines in...
1
by: Ronnie | last post by:
Hello there, I am creating a contact database and I would like my user to enter postal code (Canadian) and the city/province will be automatically filled in. I am sure this can be done and I can...
15
by: Chad A. Beckner | last post by:
Ok, here's the situation: I want to read the currently executing .aspx page "source code" from memory as it is executing so I can grab certain values from within the page (for example, say the...
18
by: Marian F. | last post by:
The 12 years old genius function to count english words in a sentence: ' This is my function to count english words in your string ' s is the string with your words to be counted ' Returns an...
0
by: pwilliams | last post by:
NCOALink Change of Address Verification Each year over 40 million Americans change their mailing addresses. This change is equivalent to every person in California deciding to change addresses...
6
by: Just Me | last post by:
Any ideas on this. I am trying to loop through an xml document to remove attributes, but Im having so much trouble, any help is appreciated //THIS IS THE EXCEPTION ( SEE CODE LINE WHERE FAILURE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.